in reply to Perl Bug in Regex Code Block?
Which says to me that perl is using the dynamic variable inside the regex eval. (Incidentally the docs do say that this is an experimental feature and may not work appropriately. Also they mention localization so I suspect this is maybe intended.) Also if you change the my to a local it produces the desired results.0: 12; @counts = (0) 1: 34; @counts = (0) 2: 56; @counts = (0) @main::counts = (6)
I get the same result again. Now uncomment the last print line and run it again. I get a#!/usr/bin/perl use strict; use warnings; use re qw/eval /; my $line = 'ab'; my $pattern = q/(.)(?{print ++$counts[0]})^/; for (0..2) { my @counts = (0); print "$_: "; $line =~ /$pattern/; print "; my \@counts = (@counts)\n"; } { no strict; no warnings; print "our \@counts = (".join(",",@counts).")\n"; #print "our \@counts = (@counts)\n"; }
Which to me doesnt make any sense at all. It should die in both cases cause the dynamic @counts is not declared, or in neither, but not like this.In string, @counts now must be written as \@counts at .\counts.pl line + 22, near "our \@counts = (@counts" Execution of .\counts.pl aborted due to compilation errors.
And I have another point of weirdness to note in the regex you are using you have placed a '^' caret at the END of the regex, which for some reason makes your print statement fire twice. If I remove the ^ it prints once. Either way I dont see what is going on here at all....
Yves
--
You are not ready to use symrefs unless you already know why they are bad. -- tadmc (CLPM)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re2: Perl Bug in Regex Code Block?
by Hofmator (Curate) on Sep 03, 2001 at 20:07 UTC |