Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Print a previous to previous of a matching line

by jethro (Monsignor)
on Oct 08, 2013 at 09:40 UTC ( #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).


Comment on Re: Print a previous to previous of a matching line
Download Code
Re^2: Print a previous to previous of a matching line
by ag88 (Initiate) 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
Node Status?
node history
Node Type: note [id://1057394]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2014-07-13 22:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (252 votes), past polls