开发者_如何学运维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.)
精彩评论