Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

variables inside an eval

0 views
Skip to first unread message

Richard Hainsworth

unread,
Oct 29, 2006, 2:34:44 PM10/29/06
to perl6...@perl.org
If I have the following

my $self = "some text";
my $nself = ~eval(q/"self is $self"/,:lang<perl5>);

then surely $nself should be "self is some text".

But it is not. $self is not set inside the eval in pugs.

But
say ~eval(q/"self is $self"/);
yields
"self is some text"

Is this correct behaviour?

If yes, then how can I use content from a scalar inside an eval with perl5?

Audrey Tang

unread,
Nov 1, 2006, 12:28:58 PM11/1/06
to Richard Hainsworth, perl6...@perl.org

在 Oct 29, 2006 4:34 PM 時,Richard Hainsworth 寫到:

> If I have the following
>
> my $self = "some text";
> my $nself = ~eval(q/"self is $self"/,:lang<perl5>);
>
> then surely $nself should be "self is some text".
>
> But it is not. $self is not set inside the eval in pugs.
>
> But
> say ~eval(q/"self is $self"/);
> yields
> "self is some text"
>
> Is this correct behaviour?

It's now fixed as of r14574 -- scalar lexical variables now pass into
Perl 5 just fine. Enjoy!

Oh, and you can now also write:

sub f ($x, $y) {
use v5;
$x + $y
}
say f(1,2); # 3

That is, any block that begins with "use v5;" is now handled by Perl
5. This should eliminate
some of the workarounds with eval('sub{}', :lang<perl5>), and it's
now made into Spec in S01 and S11.

Thanks,
Audrey

0 new messages