使用ARGV for perl获取目录(get directories using ARGV for perl)
$args = @ARGV;
foreach $ARGV (@ARGV)
{
$guitestsDir = "v:\\stuf\\comment\\logs\\$ARGV\\";
############################open logs folder#########################
if ( -d $guitestsDir ) {
opendir( DIR, $guitestsDir );
while ( defined( $pathofdir = readdir(DIR) ) ) {
next if ( $pathofdir eq "." );
next if ( $pathofdir eq ".." );
next unless (-d "$guitestsDir/$pathofdir");
push (@pathallSuites, $pathofdir);
}
closedir(DIR);
}
print "@pathallSuites\n";
嗨,我会给目录1和2作为参数。 在dir 1中,将dir a和b在dir 2 c和d中,当我运行它时print "@pathallSuites\n"; 输出将是:
a b a b c d应该是
a b c d我究竟做错了什么? 谢谢
$args = @ARGV; foreach $ARGV (@ARGV) { $guitestsDir = "v:\\stuf\\comment\\logs\\$ARGV\\"; ############################open logs folder######################### if ( -d $guitestsDir ) { opendir( DIR, $guitestsDir ); while ( defined( $pathofdir = readdir(DIR) ) ) { next if ( $pathofdir eq "." ); next if ( $pathofdir eq ".." ); next unless (-d "$guitestsDir/$pathofdir"); push (@pathallSuites, $pathofdir); } closedir(DIR); } print "@pathallSuites\n";hi, I will give directory 1 and 2 as argument. in dir 1 will be dir a and b in dir 2 c and d when I run it for print "@pathallSuites\n"; the output will be:
a b a b c dand should be
a b c dwhat am I doing wrong? thanks
最满意答案
您永远不会重置@pathAllSuites变量。 在你的foreach循环开始时,你需要自己做这件事。
foreach $ARGV (@ARGV) { $#pathAllSuites = -1; # Set the 'last index' to -1, effectively clearing it. $guitestsDir = "v:\\stuf\\comment\\logs\\$ARGV\\";You never reset the @pathAllSuites variable. At the beginning of your foreach loop, you need to do this yourself.
foreach $ARGV (@ARGV) { $#pathAllSuites = -1; # Set the 'last index' to -1, effectively clearing it. $guitestsDir = "v:\\stuf\\comment\\logs\\$ARGV\\";更多推荐
发布评论