Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: move down 2 lines in file?

by Lawliet (Curate)
on Jul 11, 2008 at 15:56 UTC ( [id://696993]=note: print w/replies, xml ) Need Help??


in reply to move down 2 lines in file?

Hmm, not sure about this method, but it works in theory.

open (file.....) while (<FILE>) { $. = 2; # $. holds the number of the last read line .....

I am not sure if it should be the one I posted above or next if $. == 1 or if $. == 2 though. I have no time to check right now. (Also, I am not sure if it starts counting at 0 or 1. Change the numbers accordingly

<(^.^-<) <(-^.^<) <(-^.^-)> (>^.^-)> (>-^.^)>

Replies are listed 'Best First'.
Re^2: move down 2 lines in file?
by halley (Prior) on Jul 11, 2008 at 18:46 UTC
    Changing $. does not move the file pointer. The only way to skip ahead without actually reading would be to use seek() which doesn't mix well with buffered variable-length line-oriented operations.

    --
    [ e d @ h a l l e y . c c ]

      Oh, alright. I thought my idea was pretty cool though~

      Can you (or anyone) confirm if the next if... method works?

      <(^.^-<) <(-^.^<) <(-^.^-)> (>^.^-)> (>-^.^)>
        Yes, you could do it like that:-

        my $linesToSkip = 2; while ( <FILE> ) { next if 0 < $linesToSkip --; # Do something here with the lines of interest. ... }

        I'd rather segregate the discarding of header lines (or whatever) from the processing of lines I'm interested in.

        my $linesToSkip = 2; my $discard = <FILE> for 1 .. $linesToSkip; while ( <FILE> ) { # Do something here with the lines of interest. ... }

        I hope this is of interest.

        Cheers,

        JohnGG

        Update: Fixed typo.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-25 05:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found