This is a beginner-best-practice question in perl. I'm new to this language. The question is:
If I want to process the output lines from a program, how can I format THE FIRST LINE in a special way?
I think of two possibilities:
1) A flag variable, once the loop is executed first time is set. But it will be evaluated for each cycle. BAD solution
2) An index-based loop (like a "for"). Then I would start the loop in i=1. This solution is far better. The problem is HOW CAN I DO IT?
I just found the code for looping over with the while ( <> ) construct.
Here you can see better:
$command_string = "par-format 70j p0 s0 < " . $ARGV[0] . "|\n";
open DATA, $command_string or die "Couldn't execute program: $!";
print "\t <div>          |-- <strong>Description</strong></div>\n";
while ( defined( my $line = <DATA> ) ) {
chomp($line);
# print "$line\n";
print "\t <div>          |   -- " . $line . "</div>\n";
}
close DATA;
Please also don't hesitate in correcting any code in here, this is my first perl poem.
Thanks!