【发布时间】:2020-08-26 23:10:52
【问题描述】:
我在使用“Learning Perl 6th Edition”第 5 章问题 1 时遇到问题。
问题是编写一个行为类似于 cat 但输出行顺序颠倒的程序。
这本书给出了答案 打印反向 ;
我正在运行 Perl v5.14.2
我的代码是:
#!/usr/bin/perl -w
print reverse <>;
在此之后,我对文件运行 chmod 755 以确保它是可执行的。
在我正在尝试的命令行上:
./tac.pl I am the walrus
我得到这个作为回报:
Useless use of reverse in void context at ./tac.pl line 3.
Can't open I: No such file or directory at ./tac.pl line 3.
Can't open am: No such file or directory at ./tac.pl line 3.
Can't open the: No such file or directory at ./tac.pl line 3.
Can't open walrus: No such file or directory at ./tac.pl line 3.
Use of uninitialized value in reverse at ./tac.pl line 3.
知道是什么导致了这个问题吗?
【问题讨论】:
-
提示:运行
cat I am the walrus- 这也不起作用。您应该将多行放入自己的文件中:cat text.txt和./tac.pl text.txt。 -
我相信这本书在后面的几行中都有这一点……即在 ./tac.pl 之后按 RETURN
-
当它使用文件作为参数时,它现在可以工作。正如 amon 以 cat 为例所示,当我需要使用文本文件时,我正在尝试错误地将命令行参数直接传递给程序。
-
Useless use of reverse in void context?行尾也有问题,因为perl没有看到print。对 Perl 的 Windows 构建使用 CRLF,在其他地方使用 LF 结尾,包括 cygwin。
标签: perl