0
問題: 看到exists argument is not a HASH or ARRAY element
需要幫助建立幾個條件搶權的關鍵。perl的 - 設立條件,找到正確的鍵在哈希
代碼:(我不知道也,如果我的條件設置是否正確需要幫助排除故障。)
my $xml = qx(@cmdargs);
my $data = XMLin($xml);
my $size=0;
# checking for error string, if file not found then just exit
# otherwise check the hash keys for filename and get its file size
if (exists $data->{class} =~ /FileNotFound/) {
print "The directory: $Path does not exist\n";
exit;
} elsif (exists $data->{file}->{path}
and $data->{file}->{path} =~/test-out-XXXXX/) {
$size=$data->{file}->{size};
print "FILE SIZE:$size\n";
} else {
# print "Nothing to print.\n";
}
# print "$data";
print Dumper($data);
我的數據: 數據結構XML文件FileNotFound
:
$VAR1 = {
'file' => {},
'path' => '/source/feeds/customer/testA',
'class' => 'java.io.FileNotFoundException',
'message' => '/source/feeds/customer/testA: No such file or directory.'
};
找到的xml文件的數據結構:
$VAR1 = {
'recursive' => 'no',
'version' => '0.20.202.1.1101050227',
'time' => '2011-09-30T02:49:39+0000',
'filter' => '.*',
'file' => {
'owner' => 'test_act',
'replication' => '3',
'blocksize' => '134217728',
'permission' => '-rw-------',
'path' => '/source/feeds/customer/test/test-out-00000',
'modified' => '2011-09-30T02:48:41+0000',
'size' => '135860644',
'group' => '',
'accesstime' => '2011-09-30T02:48:41+0000'
},
我認爲它是抱怨'存在$ data - > {class} =〜/ FileNotFound /'?試試'存在$ data - > {class}和$ data - > {class} =〜/ FileNotFound /'來代替。 – 2011-09-30 18:49:20
再看一遍,我應該檢查空的''文件'=> {}'? – jdamae
錯誤消息涉及什麼行? – 2011-09-30 18:54:04