Hi, All -
Here's a question that I cannot think of an elegant answer for and hope you may be able to help:
$my counter = 0;
while ( <> )
{
$counter ++;
print;
}
Now, if this loop is in the body of my programme, it should simply count the lines in a file handed over as an invocation argument to this script. However, if I hand over two or more invocation arguments
$counter will not reset to zero when reading in the second, third, etc. file.
Therefore my question: Is there an elegant (!) way to reset the variable back to zero for each file to read in? How can I know that Perl is now accessing the next file in the list of invocation arguments? I was thinking along the lines of a special variable that might change its value when accessing the next file or so.
For purely aesthetic reasons I want to avoid having to write something like this:
for my $file in ( @ARGV )
{
open FILE, "<", $file;
$my counter = 0;
while ( <FILE> )
{
$counter ++;
print;
}
...
}
Any ideas on this?
Thanks in advance for your help!
Best regards -
Pat