开发者

How long have Perl 5 formats been able to handle lexical variables?

开发者_如何学运维I seem to remember that Perl 5 formats only worked with package variables, and PBP seems to back that up on page 449:

Formats rely on global variables for configuration, and on package variables for the data they are to format (see Chapter 5).

But a quick test seems to show otherwise (tested with 5.8.9, 5.10.0, and 5.12.1):

#!/usr/bin/perl

use strict;
use warnings;

my $foo = "hello world";
write;

format STDOUT =
@<<<<<<<<<<<<<<<
$foo
.

Did this change in some version of Perl 5, or am I misunderstanding something?


Since 5.001? From perlform:

Lexical variables (declared with "my") are not visible within a format unless the format is declared within the scope of the lexical variable. (They weren't visible at all before version 5.001.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜