in reply to Delete all "records" which contain a regex match

Hi ilovechristy,

You say I have tried various approaches to this.  Can you show us the code you've tried, so we'll know where it is you're getting stuck?  That way, if it's a specific bug you've got, it'll be easier to find and fix it, and if it's just a matter of not knowing what to do at a certain point, we can help you get past the particular hurdle.


s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
  • Comment on Re: Delete all "records" which contain a regex match

Replies are listed 'Best First'.
Re^2: Delete all "records" which contain a regex match
by ilovechristy (Novice) on Jun 05, 2006 at 15:52 UTC
    My apologies. Here are two methods that I have tried that read in a file from stdin:

    Attempt 1:
    #!/usr/bin/perl -w undef $/; while (<>) { s/^COMMENT:\s+AUTHOR: .*?poker.*?^-----$//gsm; print; }
    Attempt 2 (completely nonsensical):
    #!/usr/bin/perl -w #undef $/; while (<>) { next unless (@foo = /^COMMENT:$/ ... /^-----$/); print if ! /poker/; # $_ =~ /poker/; # print $_, "\n"; print @foo; }
    Buddha bless you.

      Hi, ilovechristy, here is one way to do it. Also have a look at perlre.

      use strict; use warnings; local $/; my $data = <DATA>; $data =~ s/COMMENT:(?:(?!-----).)*-----//gs; print $data; output: ------- AUTHOR: bobMonk TITLE: Monk Software Chart STATUS: Publish CATEGORY: Monks DATE: 05/21/2006 11:36:16 AM -----

      Prasad