I am debugging a done-by-another-one script.

This is the snippet he did:

 ...
open OUTPUT_FILE, "$makingOutDir/$inputFile";
$_ = <OUTPUT_FILE>;
while ( defined($_) ) {
  $diff_text .= prep_for_output($_);
  $_ = <OUTPUT_FILE>;
}
close OUTPUT_FILE;

print <<EOF
Test $num_test skipped: missing output file for matching
$diff_text
EOF
 ...

I was wondering if is it possible to obtain the same behavior simplifying it doing like this:

 ...
print "Test $num_test skipped: missing output file for matching";
open OUTPUT_FILE, catfile($makingOutDir, $inputFile) or die $!;
while ( <OUTPUT_FILE> ) {
  my $diff = prep_for_output($_);

  print <<EOF
$diff
EOF
}
close OUTPUT_FILE;
 ...

or, in your opinions, there are a better and simpler way?

有帮助吗?

解决方案

It's not a massive improvement, but something like this, perhaps.

print "Test $num_test skipped: missing output file for matching";

my $filename = catfile($makingOutDir, $inputFile);
open my $out_fh, '<', $filename or die "Can't open $filename: $!";

print prep_for_output($_) while <$out_fh>;

close $out_fh;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top