Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Print a previous to previous of a matching line

by jethro (Monsignor)
on Oct 08, 2013 at 09:40 UTC ( [id://1057394]=note: print w/replies, xml ) Need Help??


in reply to Print a previous to previous of a matching line

sub getGI { my $previous1,$previous2; open(FILE, "twentySeq1e-10.out") or die("Cannot open file"); while(<FILE>) { my $line = $_; if($line=~/# 0 hits found/) { print "$previous2\n"; } $previous2= $previous1; $previous1= $line; }

The generalized solution would use an array. You use unshift() to add the line at the start of the array and you use pop() to remove the last line if the array has length n+1 (with n being the number of lines you want to remember). That is called a pipeline, queue, shift register or FIFO (first-in-first-out).

Replies are listed 'Best First'.
Re^2: Print a previous to previous of a matching line
by ag88 (Novice) on Oct 08, 2013 at 10:14 UTC

    Thankyou soo much for help it worked. Thanks alot :)

Log In?
Username:
Password:

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

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

    No recent polls found