Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: s///g and capturing all matches

by johngg (Canon)
on Dec 15, 2011 at 15:06 UTC ( [id://943756]=note: print w/replies, xml ) Need Help??


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!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://943756]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2024-04-23 09:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found