perl regex multi line cut

hello mighty all

there's a file with lots of comments.. some of them looks like:

=comment
blabla
blablabla
bla
=cut

i'm trying to cut this out completely with this code:

$line=~s/^=.+?=cut//sg;

but no luck
also tryed to change it abit but still I don't understand how the multi-line works in regex :frowning:

do you have

=comment
blabla
blablabla
bla
=cut

assigned to $line ?

i've tryed to assign all $line's to $newline throught $newline.=$line
then s///s it
same shit

$ cat t.pl
$line = <<EOF;
=comment
blabla
blablabla
bla
=cut
woohoo
EOF
$line =~ s/^=.+?=cut//sg;
print $line;
$ perl t.pl

woohoo

dude i didn't get it :frowning:
in my file with comments i don't have such $line =<<EOF;

there just lines with code and few comments blocks
so when i do while{} and getting those lines 1 by 1 what should i do to cut out

some code
=comment
blabla
=cut
some code

blocks?

Give a better example of the input file and the desired output.

Regards

Maybe something like this ?

$
$ cat f5
some code here
and some more code here
=comment
blabla
blah blah blah
more blah blah
=cut
some code here
some more code here
=comment
blah more blah
=cut
and more code...
$
$ perl -lne 'BEGIN{undef $/} s/^=.*?=cut//msg; print' f5
some code here
and some more code here
 
some code here
some more code here
 
and more code...
 
$
$

tyler_durden

==
Note that there's a blank line in the output for every comment block. If you don't want those either, then -

$
$
$ perl -ne 'BEGIN{undef $/} s/^=.*?=cut\n//msg; print' f5
some code here
and some more code here
some code here
some more code here
and more code...
$
$
$

for the same file "f5".

HTH,
tyler_durden

yes! that works. thank you
but i would like to know HOW it works :confused:

why are you use /sm ? is it not 2 different options?? for multi-line and single line?
why need undef$/ if you have /sm ?
how to make the same work in a script inside?

It sets record separator to undef, so whole file will be loaded into $_ variable.

/s effect is that "." matches any character in string, including newline.
/m causes ^ and $ to match not only begin and end of the whole string, but also newline characters inside of it.

And another one (f5 is the same as above)

$ perl -nle 'print unless /=.*?/ .. /=cut/' f5
some code here
and some more code here
some code here
some more code here
and more code...