Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
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 having an uproarious good time at the Monastery: (10)
As of 2015-07-02 13:01 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 (37 votes), past polls