Google 网上论坛不再支持新的 Usenet 帖子或订阅项。历史内容仍可供查看。

variables inside an eval

已查看 0 次
跳至第一个未读帖子

Richard Hainsworth

未读,
2006年10月29日 14:34:442006/10/29
收件人 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

未读,
2006年11月1日 12:28:582006/11/1
收件人 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 个新帖子