in reply to How to reset a variable for each file inside a while( <> ) loop?

If you want to print the line number of the current filehandle you can use the variable $. (See also perldoc perlvar - $INPUT_LINE_NUMBER).
  • Comment on Re: How to reset a variable for each file inside a while( <> ) loop?

Replies are listed 'Best First'.
Re^2: How to reset a variable for each file inside a while( <> ) loop?
by ferreira (Chaplain) on Jun 13, 2008 at 15:23 UTC

      What "perldoc" are you using?

      $ perldoc -v '$.' Ending switch processing. Args are [$.] with 0 errors. /usr/bin/perldoc => Pod::Perldoc v3.14 Formatter class Pod::Perldoc::ToMan successfully loaded! Will format with the class Pod::Perldoc::ToMan Searching for $. Looking for $. in /usr/bin /etc/perl /usr/local/lib/perl/5.8.8 /usr/lo +cal/share/perl/5.8.8 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5. +8 /usr/share/perl/5.8 /usr/local/lib/site_perl . /usr/local/sbin /usr +/local/bin /usr/sbin /usr/bin /sbin /bin /usr/games No documentation found for "$.".

      Update: ferreira has /msg'd me to tell me it's a feature added in recent developer releases. Nice; it's certainly something I've often wanted to be able to do.

Re^2: How to reset a variable for each file inside a while( <> ) loop?
by pat_mc (Pilgrim) on Jun 13, 2008 at 15:48 UTC
    Thanks for this valuable reminder, rminner!

    The only problem I see is that the special variable $. is subject to the very problem I am trying to escape from: it increases across all lines in all files in @ARGV.