我正在尝试根据从我们的数据库中获取的统计数据自动生成报告。我使用 perl 与数据库通信并将有趣的变量存储为标量/数组等。然后我想在使用 pdflatex 之前创建一个乳胶文件。但是,我在尝试将标量值传递到 pdf 时遇到了一些问题。例如,请参阅下面的代码和输出
#!/usr/bin/perl
#
#
# Description: Write a monthly report from the database using latex
#
# Parameters:
#
# History:
#
# CVS ID: $Date: 2012/03/01 16:13:03 $ $Revision: 1.1 $
########################################################################
#Add library
use lib "$ENV{HOME}/perllib";
#Call modules
use DBI; # Postgres communication functions
use File::Temp qw/tempfile/;
use File::Copy;
use Cwd;
my $date_start = '01/12/12';
my $date_stop = '31/12/12';
%hash=("01"=>"Jan","02"=>"Feb","03"=>"Mar","04"=>"Apr","05"=>"May","06"=>"Jun","07"=>"Jul","08"=>"Aug","09"=>"Sep","10"=>"Oct","11"=>"Nov","12"=>"Dec");
$date_start=~/([0-9]{2})\/([0-9]{2})\/([0-9]{2}).*/;
my $date_string = "$hash{$2}$3";
my $report_name = "$date_string"."_monthly_report.pdf";
#Pragmas
use warnings;
no warnings "uninitialized"; # Don't warn about unitialized variables#
use strict 'vars'; # Force all variables to have defined scope
my $repdir = "/home/nm/Desktop/";
my ($fh, $filename) = tempfile( SUFFIX => '.tex', DIR => $repdir);
# LaTeX Header information
print $fh <<'END';
\documentclass{article}
\usepackage{underscore}
\usepackage{fullpage}
\usepackage{multicol}
\usepackage[margin=0.5in]{geometry}
\usepackage{graphicx}
\usepackage{array}
\newenvironment{nstabbing}
{\setlength{\topsep}{0pt}%
\setlength{\partopsep}{0pt}%
\tabbing}
{\endtabbing}
\begin{document}
\begin{center}
\LARGE \bf MONTHLY SUMMARY
\end{center}
END
my $blank = " ";
# Body of LaTeX document
print $fh <<END;
This report details clinical and imaging statistics from $date_start to $date_stop
END
print $fh <<'END';
This report details clinical and imaging statistics from $date_start to $date_stop
\large \bf Clinical Statistics
\normalsize \rm
\begin{table}[h]
\centering
\begin{tabular}{cccc}
\hline
Task & AR & DB & GM \\
Cannulation & 1 & 2 & 3 \\
\hline
\end{tabular}
\end{table}
END
# Closing of LaTeX document
print $fh <<'END';
\end{document}
END
# Run LaTeX compiler to generate PDF
system('pdflatex -output-directory ' . $repdir . ' ' . $filename);
my $file_prefix = substr($filename, 0, -4);
#remove aux, log and tex files
my $auxfile = $file_prefix . ".aux";
my $logfile = $file_prefix . ".log";
my $pdffile = $file_prefix . ".pdf";
system('rm ' . $auxfile . ' ' . $logfile . ' ' . $filename);
$filename="$repdir$report_name";
move($pdffile,$filename);
system('acroread ' . $filename);
为什么
print $fh <<END;
This report details clinical and imaging statistics from $date_start to $date_stop
END
给出正确的输出,而以下没有?
print $fh <<'END';
This report details clinical and imaging statistics from $date_start to $date_stop
END
我尝试使用前者创建展示的表格,但我无法以良好的格式获得它,例如它会创建一个额外的列并在 GM 旁边放置插管。此外,当使用前者时,我必须在乳胶关键字之前放置一个额外的 /,例如 //bf 而不是 /bf 而在后者('END')中我不需要。
理想情况下,我更喜欢使用“END”作为我的表格,并且乳胶格式按预期工作。但是,我无法传递标量和数组值。我该如何管理?