in reply to Re^3: Multiple uses of (?{ code }) do not appear to be called
in thread Multiple uses of (?{ code }) do not appear to be called
I'd like to give you two reasonable workarounds. The first is simply using the global variable, with my added suggestion to enclose it in an anonymous block:
This will make sure that only foo() can see @o.{ # limit scope my @o; sub foo { my $window = "a b X20 c X5 d e X17 X12"; @o = (); my @m = ( $window =~ m/(X\d+(?{push @o, pos()}))/g ); print "Matches: @m"; print "Offsets: @o"; print " "; } }
The second workaround is basically a rewrite of your code. It doesn't solve the general issue, but it avoids the use of the complicated (?{BLOCK}) feature for your particular case:
sub foo { my $window = "a b X20 c X5 d e X17 X12"; my( @o, @m ); while( $window =~ m/(X\d+)/g ) { push @m, $1; push @o, $+[0]; } print "Matches: @m"; print "Offsets: @o"; print " "; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Multiple uses of (?{ code }) do not appear to be called
by bsdz (Friar) on Dec 29, 2006 at 14:53 UTC | |
|
Re^5: Multiple uses of (?{ code }) do not appear to be called
by diotalevi (Canon) on Dec 29, 2006 at 15:57 UTC | |
by rhesa (Vicar) on Dec 29, 2006 at 20:08 UTC |