Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: parsing with regex

by Sifmole (Chaplain)
on Nov 16, 2001 at 02:46 UTC ( [id://125709]=note: print w/replies, xml ) Need Help??


in reply to parsing with regex

#!/usr/bin/perl -w use strict; my %foo; while (<DATA>) { $foo{$1}++ if (/(\d+) is good/) } print "$_ :: $foo{$_} \n" foreach (keys %foo); __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>

Replies are listed 'Best First'.
Re: Re: parsing with regex
by 2501 (Pilgrim) on Nov 16, 2001 at 03:11 UTC
    Sorry, I probably wasn't clear enough.
    I would need everything between the horizontal breaks which would be:
    1 is good<BR> data unique to 1<BR> data unique to 1<<BR> data unique to 1<<BR> data unique to 1<<BR> 3 is good<BR> data unique to 3<<BR> data unique to 3<<BR> data unique to 3<<BR> data unique to 3<<BR>
    Thank you,
    2501
      Okay how about this?
      #!/usr/bin/perl -w use strict; my @foo; $/=""; $_ = <DATA>; while (s/(\d+ is good.*?)<HR>//s) { push @foo, $1; } print $_, "\n--------------\n" foreach (@foo); __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://125709]
help
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found