in reply to Re^2: Multiple uses of (?{ code }) do not appear to be called
in thread Multiple uses of (?{ code }) do not appear to be called
I must admit I am not too hot on closures either but another interesting observation is that making @o global appears to cure the problem.
Then perhaps instead of @::o = () you may want to use our in conjunction with local:
#!/usr/bin/perl use strict; use warnings; sub foo { my $window = "a b X20 c X5 d e X17 X12"; local our @o; my @m = $window =~ m/(X\d+(?{push @o, pos}))/g; print "Matches: @m,\n"; print "Offsets: @o,\n\n"; } foo; foo; foo; __END__
|
|---|