Dear Ben,
> > > another bad point about eval is that it can access and modify lexicals
> > > and globals anywhere in the code. so that can lead to action at a
> > > distance and very hard to find bugs.
> > [...]
> I'm not sure if this is what is referred to, but it applies.
>
> If this is dynamic code where the string to be evaled is
> passed in from elsewhere, then one problem is that you
> might wind up picking up lexicals in the scope of the
> eval, and being unable to pick up lexicals in the scope
> where you tried to create the eval. Closures would get
> this right.
>
> Ruby solves this problem by giving you a number of
> variations on eval, one of which evals things in the
> context of your caller. Still not perfectly general, but
> much more likely to be right in this instance.
Do you mean examples like below?
----------------------\/--------BEGIN---------\/----------------------
% perl -le 'my $x = 7; my $str = q{print ++$x}; {my $x = 11; eval $str}'
12
%
----------------------/\---------END----------/\----------------------
IMHO the current behaviour is intuitive. And I certainly don't
see "action at a distance". The person who thinks that the '$x' inside
$str is referring to the currently visible $x (value 7) is simply
mistaken. Likewise the person who thinks that the inner $x will remain
untouched by the eval(). (But maybe this latter is what Uri is
referring to as "action at a distance".)
peace, || What can one hour achieve?
--{kr.pA} || http://www.workanhour.com/
--
Kid, n.: A noise with dirt on it.
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm