使用ARGV for perl获取目录(get directories using ARGV for perl)

编程入门 行业动态 更新时间:2024-10-28 14:27:02
使用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 d

and should be

a b c d

what 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\\";

更多推荐

本文发布于:2023-08-05 16:15:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1434769.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:目录   ARGV   perl   directories

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!