我有一个脚本,它以询问用户文件名开始。我想添加一个功能,以便我可以在运行程序之前在命令行中提供文件名。
直截了当:如果我使用“perl wordcounter.pl text.txt”启动我的程序,我如何从代码中访问程序名称(即 text.txt)之后的字符串?
我开始做类似的事情:
$filename = "Filename supplied in the commandline";
if ($filename == 0) {
print "Word frequancy counter.\nEnter the name of the file that you wish to analyze.\n";
chomp ($filename = <STDIN>);
}
基本上,如果命令行没有提供文本文件,$filename 仍然是 0,然后它会继续请求文件。
任何人都知道我如何访问代码中的“命令行中提供的文件名”?