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>