-1

わかりました、これは私を夢中にさせています!!

多くの例を見て、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) {'

誰にもアイデアはありますか??

4

3 に答える 3

6

「if」の上のすべての行は有効な Perl ではありません。私はあなたがやりたかったと信じています:

#!/usr/bin/perl
use strict;
use warnings;

##########################
#### Define Variables ####
##########################

my $mainDirectory = "$ENV{HOME}/test";
my $file = 'report.txt';
my $backupDirectory = "$ENV{HOME}/test/backup";
my $number_to_try = 0;

##################################
#### Check if the file exists ####
##################################

my $filename = "$mainDirectory/$file";
print "$filename\n";

if (-e $filename) {
        print "File Exists!\n";
}
于 2013-08-23T20:47:59.930 に答える
1

最小限の変更で書き直されました:

#!/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!"
}

use strict;andを使用することを強くお勧めしuse warnings;ます。

于 2013-08-23T20:45:53.323 に答える