Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
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 ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://691925]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-03-28 20:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found