问题出现在打印行。请帮助,因为我是编程新手。我的问题是变量不会在子例程语句中保持共享,并且 PDF 文件行的 #Path 处存在未知的正则表达式修饰符“/v”和“/e”。
# Path to the PDF file
my $pdf_file = 'path/to/your/file.pdf';
# Size threshold in kilobytes
my $size_threshold_kb = 1_000_000;
# Get the file size in bytes
my $file_size_bytes = -s $pdf_file;
# Convert bytes to kilobytes
my $file_size_kb = $file_size_bytes / 1024;
# Check if the file size is less than the threshold
if ($file_size_kb < $size_threshold_kb) {
# Perform PDF impression reconciliation
reconcile_pdf_impression($pdf_file);
} else {
# Log that no reconciliation happened
log_no_reconciliation($pdf_file);
}
sub reconcile_pdf_impression {
my ($file) = @_;
# Replace with actual reconciliation logic
print "Performing PDF impression reconciliation for $file.\n";
}
sub log_no_reconciliation {
my ($file) = @_;
open my $log_fh, '>>', 'reconciliation.log' or die "Could not open log file: $!";
print $log_fh "No reconciliation performed for $file because its size is $file_size_kb KB.\n";
close $log_fh;
}
我试图打印文件大小,在 pdf 中添加一个条件,如果大小低于 1,000,000,那么它将进行印象核对,并在没有印象核对的情况下创建日志。
要与子程序共享变量,您需要:
my $a = 1;
foo($a);
sub foo {
// $a is not visible here
my ($b) = $@;
print "$b\n";
}
our $a = 1;
foo;
sub foo {
print "$a\n";
}