好吧,这让我疯狂!我的Perl语句有什么问题?
看了很多例子,并阅读了perl中的if语句,并且所有内容对我来说都是正确的,所以其他人可以发现错误吗?
#Start of script
#!/usr/bin/perl -w
##########################
#### Define Variables ####
##########################
echo $PWD;
mainDirectory=$ENV{HOME}"/test/";
file='report.txt';
backupDirectory=$ENV{HOME}"/test/backup";
number_to_try=0;
##################################
#### Check if the file exists ####
##################################
filename=$mainDirectory$file;
echo $filename;
if (-e $filename) {
print "File Exists!"
}
错误消息我得到的是:
./perl.pl: line 18: syntax error near unexpected token `{'
./perl.pl: line 18: `if (-e $filename) {'
人有什么想法?
这个Perl怎么样? – Jean
其开始的perl脚本...#!/ usr/bin/perl ..它怎么样? – Fuzzybear
这主要写在'sh'中,除了结尾的条件和'%ENV'哈希。使用错误的shebang不会奇迹般地解决这个问题。 Perl没有'echo'。变量被赋值为'$ foo ='$ ENV {HOME}/test /“;'(注意LHS上的$ $ sigil) – amon