Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re^2: move down 2 lines in file?

by halley (Prior)
on Jul 11, 2008 at 18:46 UTC ( #697057=note: print w/replies, xml ) Need Help??

in reply to Re: move down 2 lines in file?
in thread move down 2 lines in file?

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 ]

Replies are listed 'Best First'.
Re^3: move down 2 lines in file?
by Lawliet (Curate) on Jul 11, 2008 at 19:30 UTC

    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.



      Update: Fixed typo.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://697057]
Eily just learned that you get a message when replying to yourself
[Eily]: "Hey I got an answer!" => "Oh, right, it's me..."
[stonecolddevin]: good morning all
[Eily]: good morning stonecolddevin :)
[jedikaiti]: Hey, it's a stonecolddevin

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (11)
As of 2017-11-22 18:39 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (327 votes). Check out past polls.