开发者

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

开发者 https://www.devze.com 2023-01-24 01:45 出处:网络
开发者_如何学运维I seem to remember that Perl 5 formats only worked with package variables, and PBP seems to back that up on page 449:

开发者_如何学运维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

精彩评论

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