in reply to s///g and capturing all matches

Rather than a global match you could use a while statement modifier.

knoppix@Microknoppix:~$ perl -E ' > $file = <<EOD; > some data; comment 1 > more data; comment 2 > even more data; comment 3 > EOD > push @comments, $1 while $file =~ s{(;[^\n]*)}{*MARKER*}; > say $file; > say for @comments;' some data*MARKER* more data*MARKER* even more data*MARKER* ; comment 1 ; comment 2 ; comment 3 knoppix@Microknoppix:~$

I hope this is of interest.

Cheers,

JohnGG

Replies are listed 'Best First'.
Re^2: s///g and capturing all matches
by Random_Walk (Prior) on Dec 16, 2011 at 09:52 UTC

    Hi JohnGG,

    I had tried the while but could not get the syntax right. Thanks for pointing me down the right path.

    Cheers,
    R.

    Pereant, qui ante nos nostra dixerunt!