Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

assign a value to $INPUT_LINE_NUMBER

by HYanWong (Acolyte)
on Mar 04, 2013 at 14:21 UTC ( #1021653=perlquestion: print w/ replies, xml ) Need Help??
HYanWong has asked for the wisdom of the Perl Monks concerning the following question:

I'm reading my way through a large (18GB) text file, then seeking to the start of the file again for re-reading (I don't want to close and re-open the filehandle).

I'd like to give some feedback about how far through the file I am, so I'm checking the value of $. and printing every millionth line, as a check using unless($. % 1000000). When I seek to the start again, $. is not reset, so different lines are printed. So I'd like to set $.= 0 just before my seek(FILE,0,0). Is assigning to $. considered bad form, or inadvisable? I'd prefer not to use my own variable to keep track of line count - it seem neater to use the built-in one.

Comment on assign a value to $INPUT_LINE_NUMBER
Download Code
Re: assign a value to $INPUT_LINE_NUMBER
by choroba (Canon) on Mar 04, 2013 at 14:38 UTC
    Setting $. when seeking is OK. Sometimes, I even use
    seek $FH, $. = 0, 0;
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: assign a value to $INPUT_LINE_NUMBER
by Anonymous Monk on Mar 04, 2013 at 22:50 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1021653]
Approved by tmharish
Front-paged by davido
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (18)
As of 2015-07-02 16:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (44 votes), past polls