On Mon, Nov 15, 2004 at 06:17:44PM +0000, Brian McCauley wrote:
> > I didn't mean to say that the behaviour is buggy.
> 
> But, in fact, it is.

Er, no is isn't .... ;-)
 
> 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.

No it shouldn't. The basic guiding principle is that if the code
is contained within a literal string, then you don't need use re 'eval'.
If it's the result of an expression, then it's suspect.

> 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.

At the moment they behave as if they are within a hidden inner named sub,
which doesn't do the right thing most of the time. I want $x to behave as
if it's part of the enclosing sub. ie currently this fails:

    sub foo { my ($x) = @_; /stuff...(?{ $x == something })..../ }
    foo(1);
    foo(2); # error - regex thinks $x is still 1

I want to it to behave scope- and closure-wise a bit like:

    sub foo { my ($x) = @_; /stuff.../ && do { $x == something } && /..../ }
 
> 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.

I want to fix 1-4, but have doubts about the best way to fix 1,2,4.

> 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.

That was never the suggestion. My fallback plan if I couldn't come up with
anything better was to make 4 fail in the absence of a use re 'eval'; but
I think I can avoid that now.

> Another is that 1 and 4 should emit warings.  This I would agree is 
> probably a good idea.

Quite possibly.

> 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 } })';

-- 
The warp engines start playing up a bit, but seem to sort themselves out
after a while without any intervention from boy genius Wesley Crusher.
    -- Things That Never Happen in "Star Trek" #17

Reply via email to