Yitzchak Scott-Thoennes wrote:
On Mon, Nov 15, 2004 at 12:06:55PM +0000, Brian McCauley wrote:
So what you are saying is that 'use re "eval";' setting is implicitly on during constant folding and is not what one would consider the "Right Thing(TM)".
Not exactly; I'm saying that $foo =~ EXPR never requires a use re "eval" if EXPR is a constant or something that folds to a constant. matching isn't actually done during constand folding.
Those two statements do not differ in terms of the behaviour they describe. (They differ only in emphasis).
By "the problem", I meant that it is an existing behaviour where
preserving backward compatibility makes it harder for Dave to do his
long-awaited fix for (?{ })'s variable binding.
Ah, now I can see where I was being dense. If Dave's fix for variable scoping in (?{}) had the side-effect of also fixing the bug wrt constant folding then any legacy code that was expoiting the bug would break.
> I didn't mean to say that the behaviour is buggy.
But, in fact, it is.
Let's see if I've got it straight.
Currently AFAIK samples 1-5 below do the same thing.
In a perfectly consitant world sample 4 should be an error. Samples 1, 2 and 5 should do the same thing but this may not be quite the same thing as sample 3 because in samples 1 and 2 $x should behave as if it is inside an eval(STRING) (as it is in 5) whereas in sample 3 it is not.
Dave wants to correct the anomoly in the behavior of sample 3 wrt to the scoping of $x so that it does not behave as if it were inside string eval.
However this is where things start to get confusing.
One suggestion seems to be to change the behaviour of samples 1 and 4 such they remain equivalent to sample 3. This would be wrong. Sample 1 should remain equivalent to samples 2 an 5.
Another is that 1 and 4 should emit warings. This I would agree is probably a good idea.
Sample 1 use re 'eval'; $foo =~ '(?{ $x = 1 })';
Sample 2
use re 'eval';
my $re = '(?{ $x = 1 })';
$foo =~ $re;Sample 3
no re 'eval';
$foo =~ /(?{ $x = 1 })/;Sample 4
no re 'eval';
$foo =~ '(?{ $x = 1 })';Sample 5
no re 'eval';
$foo =~ '(?{ eval q{ $x = 1 } })';