Re: [MacPerl-AnyPerl] regexp matching newline

[email protected] (John Delacour) Sun, 17 Aug 2003 00:32:24 +0100
Newsgroups perl.macperl.anyperl
Message-ID <p06001d0fbb646c9a9096@[10.0.0.4]>
At 11:45 pm +0100 16/8/03, John Delacour wrote:
>At 7:34 pm +0200 13/8/03, allan juul wrote:
>>
>>i want t achieve:
>>----------------------
>>test0;
>>test1;
>>test3;
>
>
>I'd do it like this:
>
>[...]
>foreach (@lines) {
>   s~^//~~ ;
>   print qq~$_$newlinechar~ ;
>}

Sorry -- I misread your last bit.  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) {
    print qq~$_$newlinechar~ if ! m~^//~ ;
}

or this:

#!/usr/bin/perl
$_ = qq~test0;
test1;
//test2;
//test2;
test3; ~;

s~^//.*$/~~gm;
print;