我有一个脚本,它采用太旧的路径名/文件(由用户输入决定)并删除它们。我想分别列出每个目录,并要求确认删除每个目录中的旧文件。
所以,我有一个包含多个数组(每个目录)的数组(@oldDirs),其中包含字符串(全路径名称)。
@oldDirs = (@AirDefense,@Arcsight,@Avocent,@BlueCoat,@Checkpoint,@Cisco,@Crossbeam,@FireE ye,@lostAndFound,@rancid,@Riverbed,@Symantec,@Wiki,@WLAN)
if($oldPathsSize != 0)
{
my $dirNamesCounter = 0;
my @dirNames = ('/AirDefense','/Arcsight','/Avocent','/BlueCoat','/Checkpoint','/Cisco','Crossbeam','FireE ye','/lost+found','/rancid-2.3.8','/Riverbed','/Symantec','/Wiki','/WLAN');
foreach my @direc (@oldDirs)
{
my $size = @direc;
print "Confirm Deletion of $size Old files in $dirNames[$dirNamesC]: \n";
$dirNamesCounter++;
foreach my $pathname (@direc)
{
print "\t$pathname\n";
}
print "\nDelete All?(y/n): ";
my $delete = <STDIN>;
chomp($delete);
if($delete eq "y")
{
#delete file
}
}
}
我的问题是第一个 foreach 语句。两者都是数组,不允许使用@direc,因为我需要在 foreach 的那部分有一个标量值……但它们都是数组!如果可能的话,我该怎么做?