Perl-Sensitive Sunglasses | |
PerlMonks |
How to reset a variable for each file inside a while( <> ) loop?by pat_mc (Pilgrim) |
on Jun 13, 2008 at 13:59 UTC ( [id://691905]=perlquestion: print w/replies, xml ) | Need Help?? |
pat_mc has asked for the wisdom of the Perl Monks concerning the following question:
Hi, All -
Here's a question that I cannot think of an elegant answer for and hope you may be able to help:
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:
Any ideas on this? Thanks in advance for your help! Best regards - Pat
Back to
Seekers of Perl Wisdom
|
|