Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Localization gotcha?

by benizi (Hermit)
on May 19, 2005 at 19:38 UTC ( [id://458752]=note: print w/replies, xml ) Need Help??


in reply to Re: Localization gotcha?
in thread Localization gotcha?

Thanks for the suggestion, though I solved my actual problem per the response below (localizing $. wherever my module performed a seek() or used <>).

Instead of using IO::File as you propose, since open()'ed files are automatically IO::Handles, you can just "use IO::Handle;" to provide the input_line_number method (note the continue):

use strict; use warnings; use IO::Handle; while (<>) { my $lineno = ARGV->input_line_number; # print a status message every 100 lines warn "Processing $ARGV line $lineno\n" unless $lineno % 100; # do some processing stuff } continue { close ARGV if ARGV->eof; # else input_line_number won't reset per- +file }

(Update:) s/eof/ARGV->eof/ in the code example. (else a poorly written function, like my original seeky() would let the eof refer to the wrong file)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-03-29 07:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found