But as anything else you can always set the values of $' and $` to a variable and use those variables later on:my $line='0x160001a \"fubar - BlahBlahBlah - Blah Blah (1:23)\": ("Foo +" "Bar") Baz'; if ($line=~/\)/){ $line="$`)"; } if ($line=~/-\s/){ $line=$'; }
And you can use both $' and $` after you get a successful match in the current dynamic scope (as long as you are still in the current dynamic scope). Though I would probably solve the problem differently than you are doing by the same reasoning as you above.use strict; use warnings; my ($prematch,$postmatch); my $line='0x160001a \"fubar - BlahBlahBlah - Blah Blah (1:23)\": ("Foo +" "Bar") Baz'; if ($line=~/\)/){$line="$`)"; $prematch = $`;} if ($line=~/-\s/){$line=$'; $postmatch = $';} print $prematch,$/; print $postmatch,$/; print $line,$/;
Here comes my simple question: since the first - occurs before the values that I want, and because the first ) occurs afterwards,
which captures in $1 what you described, and doesn't suffer from the performance penalty of using $' or $`use strict; use warnings; my $line='0x160001a \"fubar - BlahBlahBlah - Blah Blah (1:23)\": ("Foo +" "Bar") Baz'; if ( $line =~ /- ([^\)]+\))/ ) { print $1; $line = $1;}
-enlil
In reply to Re: Simple re question
by Enlil
in thread Simple re question
by DarknessX
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |