Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
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 contemplating the Monastery: (13)
As of 2015-07-30 17:05 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 (273 votes), past polls