今日のSQL文を実行しようとしています。たとえば、「今日が25日ならばSQLを実行し、それ以外の場合は今日は有効な累計ではありません」月のある特定の日にのみSQLを実行する
私は接続して、いくつかのHTMLを構築する前に、いくつかのSQLを実行するためにDBI
を使用している基本的
は、自動的に電子メールで送信する
をしかし、私は次のような構文エラーを取得しています:。
構文エラーでXXXXX、近くに "、そうでない場合は" (暴走複数行{ }文字列XXから始まる) 行末のXXXXXに右括弧または角括弧がありません。
私は、(私がやっていると思われる)式の中に命令を直接埋め込むことはできないと読んでいます。このスクリプトは、day要素とelse
ステートメントなしでうまくいきました。
# Get the current day of the month (along with other date parts we can ignore)
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time);
## Filter based on day of week
my $sql;
if ($mday == 25) {
$sql = qq{<MY SQL STATEMENT HERE>
}
else {
say "Today is not a valid rundate";
}
## Prepare and execute the SQL
my $sth = $dbh->prepare($sql) or die "Failed to prepare SQL: " . $dbh->errstr;
$sth->execute() or die "Failed to execute SQL: " . $dbh->errstr;
## Start building the HTML output
my $html = qq{
<table style="width:100%"><thead>
<tr>
<th>#</th>
<th>col1</th>
<th>col2</th>
<th>col3</th>
</tr>
</thead>
};
## Loop round each row in the result set, and add to the HTML output for each one.
my $count = 0;
while (my $row = $sth->fetchrow_hashref) {
#
# process rows
$count++;
#say Dumper $row;
#say "$row->{col1}, $row->{col2}, $row->{col3}";
$html .= qq|
<tr>
<td align="right">$count.</td>
<td>$row->{col1}</td>
<td>$row->{col2}<td>
<td>$row->{col3}</td>
</tr>
|;
}
## Close the HTML
$html .= "</table>";
say "$count rows processed.";
$html .= "<h2>Report SQL</h2>The report was produced with the following SQL<p><pre>$sql</pre>";
## Send the mail
my $sender = new Mail::Sender();
$sender->Open({
from => 'email1',
to => $maildest,
subject => $mailsubj,
ctype => "text/html",
encoding => "quoted-printable",
smtp => "localhost"
}) or die $Mail::Sender::Error, "\n";
$sender->SendEnc($html);
$sender->Close();
$dbh->disconnect;
これは[mcve]これは単なる転記エラーかもしれませんが、 '$ sql = qq { 'の文で' qq'を閉じたことはありません。 –
ThisSuitIsBlackNot