in reply to Re^2: How to reset a variable for each file inside a while( <> ) loop?
in thread How to reset a variable for each file inside a while( <> ) loop?

The continue allows you to call next in the loop without skipping "close ARGV if eof;".

Replies are listed 'Best First'.
Re^4: How to reset a variable for each file inside a while( <> ) loop?
by pat_mc (Pilgrim) on Jun 15, 2008 at 19:32 UTC
    Thanks to all who took the time to reply and contribute to the discussion from which I learnt a lot!

    Based on the comments made I'd like to summarise the - in my view most elegant - solution to my question here: eof permits to detect the end of file, $ARGV holds the name of the file currently read and $. holds the current line number in that file.
    I just tested the following code snippet and it does exactly what I was looking for:
    while ( <> ) { print "Reading line $. in file $ARGV.\n"; $. = 0 if eof; }

    So, thanks again to all of you who contributed!

    Cheers -

    Pat
      I'd recommend to follow what toolic advised: close the file instead of manually nulifying $. The value of $. is reset automatically when the file is closed, so the following does what you need:
      while (<>) { print "$ARGV.$.:$_\n"; close ARGV if eof; }