Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

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 ( #691925=note: print w/replies, xml ) Need Help??


in reply to Re: 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?

$. won't hold the line number of the current file when iterating via <>.

Because "<>" never does an explicit close, line numbers increase across ARGV files (but see examples in "eof" in perlfunc).

from perldoc -v '$.' (the same section of perlvar you mentioned).

Update: you need eof trick toolic mentions.

Update:: Ok. I cheated (as noticed at Re^3: How to reset a variable for each file inside a while( <> ) loop?) -- to use perldoc -v you need a brand new Pod::Perldoc like the one at Pod-Perldoc-3.14_07.

Replies are listed 'Best First'.
Re^3: How to reset a variable for each file inside a while( <> ) loop?
by Porculus (Hermit) on Jun 14, 2008 at 14:22 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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://691925]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (2)
As of 2020-10-26 08:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (250 votes). Check out past polls.

    Notices?