Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: grab only if pattern matches previous line

by Albannach (Monsignor)
on Jul 09, 2003 at 21:39 UTC ( [id://272834]=note: print w/replies, xml ) Need Help??


in reply to grab only if pattern matches previous line

This is a slightly different take on Tomte's concept, remembering that we only want it to catch specific request lines. Though pzbagel's approach is also good, this one has the advantage of not needing the data in an array (you could read it directly from a file), and not requiring the following line(s) of interest to be at fixed offsets from the 'request' line. In pzbagel's version you could read ahead if using a file, but that's a bit more messy as you need to check for EOF at each read. How you end up doing it will depend on further examination of your data, and some consideration of what else you might have to do with it later.
my $buf; for my $line (@lines) { if($line =~ /^request\((.+)$/ ) { $buf = $1; undef $buf if $buf =~ /BADSTRING/; }elsif(defined $buf) { print "$buf: ", (split ', ', $line)[1],"\n"; undef $buf; } }

--
I'd like to be able to assign to an luser

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-03-30 05:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found