Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: parsing with regex

by YuckFoo (Abbot)
on Nov 16, 2001 at 03:39 UTC ( [id://125722]=note: print w/replies, xml ) Need Help??


in reply to parsing with regex

I'm sure someone will post an efficient regex, but in the meantime you can try this. Still a bit ugly, lines are joined then split on the HR tags.

YuckFoo

#!/usr/bin/perl use strict; my ($line, @keep); for $line ((split(/<HR>\s+/s, join('', (<DATA>))))) { if ($line =~ m{\d+\s+is\s+good}) { push (@keep, $line); } } for $line (@keep) { print "$line\n"; } __DATA__ <HR> 1 is good<BR> useless data<BR> useless data<BR> useless data<BR> useless data<BR> <HR> 2 is not good <BR> useless data<BR> useless data<BR> useless data<BR> useless data<BR> <HR> 3 is good<BR> useless data<BR> useless data<BR> useless data<BR> useless data<BR> <HR> 4 is not good <BR> useless data<BR> useless data<BR> useless data<BR> useless data<BR> <HR>

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-04-23 20:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found