目前,我正在学习如何使用perl,遵循
http://www.perl.com/pub/2000/11/begperl3.html。
我现在遇到了元字符部分,当我在eclipse中运行代码时,我得到了以下错误: Name "main::URLLIST“只使用一次:可能有拼写错误Metacharacters.pl
#!/usr/bin/perl
use strict;
use warnings;
use feature ":5.10";
for my $line (<URLLIST>) {
# "If the line starts with http: and ends with html...."
if (($line =~ /^http:/) and
($line =~ /html$/)) {
say $line;
}
}你能告诉我为什么会发生这种情况吗?
发布于 2015-12-28 01:20:07
您将URLLIST视为一个文件句柄,但您从未打开它。只需使用<>,它将从作为参数传递的文件名中读取,如果没有提供参数,则从STDIN中读取。
提示:您应该使用while (my $line = <>)而不是for my $line (<>),因为后者在循环开始之前不必要地将整个文件加载到内存中。
https://stackoverflow.com/questions/34482095
复制相似问题