gpt4 book ai didi

perl - 找不到错误 "Global symbol @xx requires explicit package name"

转载 作者:行者123 更新时间:2023-12-02 09:33:44 25 4
gpt4 key购买 nike

我检查了可能已经有答案的问题,但没有一个有帮助。

这是我的 Unix 编程学期项目。我创建了一个脚本,用于将网站上的 HTML 文件与其他文件进行比较。

该脚本按预期完美运行,直到我尝试实现第二个网站,因此我又删除了为第二个网站添加的代码,现在出现错误

Global symbol "@master" requires explicit package name
Global symbol "@child" requires explicit package name

csite_md5子例程内。我已经把代码检查了很多遍了,但看不出问题所在。

我正在寻找另一双眼睛,看看我是否只是错过了一些简单的东西,通常就是这种情况。

此外,我对 Perl 还很陌生,因为这是我第一次使用该语言。

#!/usr/bin/perl

use strict;
use warnings;

use Digest::MD5 qw(md5_hex);
use File::Basename;

# Path to the c-site download root directory
my $csite_dir = '/root/websites/c-site/wget/';

opendir my $dh, $csite_dir or die $!;

# Finds the sub directories c-site_'date +%F' where the c-site download is located
my @wget_subdir_csite = sort grep /^[^.]/, readdir $dh;

# Creates the absolute path to the c-site download
my $csite_master_dir = "$csite_dir$wget_subdir_csite[0]/dayzunderground.webs.com";
my $csite_child_dir = "$csite_dir$wget_subdir_csite[1]/dayzunderground.webs.com";

# Call to subroutine to append the .html file name to the absolute path
my @master_csite = &gethtml_master_csite($csite_master_dir);
my @child_csite = &gethtml_child_csite($csite_child_dir);

&csite_md5(\@master_csite, \@child_csite);

sub gethtml_master_csite{

my ($master_path) = @_;
opendir (DIR, $master_path) or die $!;

# Ends with .html and is a file
my @html_master = sort grep {m/\.html$/i && -f "$master_path/$_"} readdir(DIR);

my @files_master = ("$master_path/$html_master[0]","$master_path/$html_master[1]","$master_path/$html_master[2]","$master_path/$html_master[3]");

return @files_master
}
sub gethtml_child_csite{

my ($child_path) = @_;
opendir (DIR, $child_path) or die $!;

# Ends with .html and is a file
my @html_child = sort grep {m/\.html$/i && -f "$child_path/$_"} readdir(DIR);

my @files_child = ("$child_path/$html_child[0]","$child_path/$html_child[1]","$child_path/$html_child[2]","$child_path/$html_child[3]");

return @files_child
}

sub csite_md5{

my ($master, $child) = @_;

if(&md5sum($master[0]) ne &md5sum($child[0])){

my $filename = basename($master[0]);
system("diff -u -d -t --width=100 $master[0] $child[0] > ~/websites/c-site/diff/c-site-$filename-`date +%F`");

#print "1"
}
if(&md5sum($master[1]) ne &md5sum($child[1])){

my $filename2 = basename($master[1]);
system("diff -u -d -t --width=100 $master[1] $child[1] > ~/websites/c-site/diff/c-site-$filename2-`date +%F`");

#print "2"
}
if(&md5sum($master[2]) ne &md5sum($child[2])){

my $filename3 = basename($master[2]);
system("diff -u -d -t --width=100 $master[2] $child[2] > ~/websites/c-site/diff/c-site-$filename3-`date +%F`");
#print "3"
}
if(&md5sum($master[3]) ne &md5sum($child[3])){

my $filename4 = basename($master[3]);
system("diff -u -d -t --width=100 $master[3] $child[3] > ~/websites/c-site/diff/c-site-$filename4-`date +%F`");

#print "4"
}
}

sub md5sum{
my $file = shift;
my $digest = "";
eval{
open(FILE, $file) or die "Can't find file $file\n";
my $ctx = Digest::MD5->new;
$ctx->addfile(*FILE);
$digest = $ctx->hexdigest;
close(FILE);
};
if($@){
print $@;
return "";
}
return $digest
}

最佳答案

$master$child 是数组引用;像 $master->[0] 一样使用它们。 $master[0] 使用数组 @master,这是一个完全独立的变量。

关于perl - 找不到错误 "Global symbol @xx requires explicit package name",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29874192/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com