Re: [MacPerl-AnyPerl] regexp matching newline

[email protected] (John Delacour) Sat, 16 Aug 2003 23:45:26 +0100
Newsgroups perl.macperl.anyperl
Message-ID <p06001d0ebb6462e24967@[10.0.0.4]>
At 7:34 pm +0200 13/8/03, allan juul wrote:
>hello
>
>i have a problem removing blank lines in one regexp. my string will 
>be slurped so it will contain newlines as examplified below:
>
>my $str = qq(test0;
>test1;
>//test2;
>test3;);
>
>$str =~ s,^.*//.+;$,,igm;
>
>print $str;
>
>__END__
>
>i want t achieve:
>----------------------
>test0;
>test1;
>test3;


I'd do it like this:


#!/usr/bin/perl
my $newlinechar = $/ ;
my @lines = split $newlinechar, <<END_OF_LINES;
test0;
test1;
//test2;
test3;
END_OF_LINES

foreach (@lines) {
   s~^//~~ ;
   print qq~$_$newlinechar~ ;
}