bratwiz has asked for the wisdom of the Perl Monks concerning the following question:
I want to do this:
my $line = 'marker <this> <that> <other>'; my $rex = qr/(?:^marker\s|\G)<(.*?)>(?: |$)/g; my @matches = ($line =~ $rex);
But it doesn't work -- can't use the '/g' modifier for some reason when defining the regex !!??!
But this does work:
my @lines = ( 'notmarker <blah> <foo> <bar>', 'marker <this> <that> <other>', 'notmarker <blech> <phooey>', ); foreach (@lines) { chomp; if (my @matches = (/(?:^marker\s|\G)<(.*?)>(?: |$)/g)) { print join(', ', @matches)."\n"; } }
How can I achieve what the second example does using precompiled patterns???
I'm stumped. I'm sure there is some smart perl person here who can help !?!?
Edited by planetscape - removed pre tags, replaced with code tags
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Global Modifier on a Pattern -- HOW!?!?!?
by duff (Parson) on Mar 24, 2006 at 06:42 UTC | |
|
Re: Global Modifier on a Pattern -- HOW!?!?!?
by tirwhan (Abbot) on Mar 24, 2006 at 06:42 UTC | |
by bratwiz (Sexton) on Mar 24, 2006 at 14:37 UTC |