Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Extract lines and output...

by jeroenes (Priest)
on Oct 10, 2001 at 00:09 UTC ( #117851=note: print w/ replies, xml ) Need Help??


in reply to Extract lines and output...

There are so many ways to do this. Maybe straightforward, don't print until $. is 4 (see perlvar):

while(<>){ next if $. <4; #codeblockdoingsomeotherthings print; }

HTH,

Jeroen

Update: I couldn't resist adding some more possibilities:

#1 slurping the whole thing in memory, and splice @file = <>; splice @file, 0, 4; print @file; #2 using the flip-flop operator while (<>){ next unless $.>3 .. 1; #... print; } #3 another flip-flop $start = -3; while (<>){ next unless $start++ .. 1; #.... print; } #4 just repeat 4 times $dummy=<> for 1..4; #5 make it multifile proof while (<>){ close( ARGV) if (eof);  next unless $.>3 .. eof; #... print; }


Comment on Re: Extract lines and output...
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (14)
As of 2014-11-24 15:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (142 votes), past polls