Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: move down 2 lines in file?

by almut (Canon)
on Jul 11, 2008 at 14:55 UTC ( [id://696982]=note: print w/replies, xml ) Need Help??


in reply to move down 2 lines in file?

In case you want to get rid of the $_ = <FILE>, you could also write something like

my $skip_n = 0; while (<FILE>) { next if $skip_n && $skip_n--; if (/blah/) { $skip_n = 2; # schedule the skipping of two lines } }

Replies are listed 'Best First'.
Re^2: move down 2 lines in file?
by ruzam (Curate) on Jul 12, 2008 at 17:42 UTC
    ++

    The beauty of this approach is that you don't find your code trying to read past the end of the file just to skip lines.
Re^2: move down 2 lines in file?
by bibliophile (Prior) on Jul 14, 2008 at 15:52 UTC
    Also, if you don't know how many lines to skip but you *do* know what the first line-of-interest starts with, you can say something like (untested):
    my $good_start = 0; while (<FILE>) { next unless (($good_start) || (/^start-of-data pattern/); $good_start = 1; # do things with the interesting lines }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-04-25 20:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found