perl - Perl 5 格式能够处理词法变量多久了?

标签 perl format

我似乎记得 Perl 5 格式仅适用于包变量,并且 PBP似乎在第 449 页上支持了这一点:

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

但快速测试似乎表明情况并非如此(使用 5.8.9、5.10.0 和 5.12.1 进行测试):

#!/usr/bin/perl

use strict;
use warnings;

my $foo = "hello world";
write;

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

这在 Perl 5 的某些版本中是否发生了变化,还是我误解了什么?

最佳答案

从 5.001 开始?来自 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.)

关于perl - Perl 5 格式能够处理词法变量多久了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4138318/

相关文章:

regex - 有没有办法计算 Perl 正则表达式匹配的次数?

linux - 当我从 Perl 调用时,为什么我的 awk 单行代码不起作用?

web-services - perl 500 SSL 协商失败

format - DOS格式和MAC格式的区别

excel - 在 Excel 中格式化公式的 VBA 数字

c++ - 制作 map 编辑器的语言/GUI库

zip - .doc 格式如何工作?

java - 需要更改我的 Android 应用程序中的日期格式

r - 在 r 中格式化数据框上的列

perl - 如果 AUTOLOAD 失败,则传递错误消息