yulivee07 has asked for the wisdom of the Perl Monks concerning the following question:
I pass this script a file containing a list of directories (filename is test):#!/usr/bin/perl -w use strict; use warnings; use File::Basename; sub remove_files_in_empty_directories($) { my ($directory) = @_; # do nothing if the directory is not empty # This is the problematic part return if glob("$directory/*"); # directory is empty, remove the .Ecurep-Lenovo* files foreach my $file ( glob("$directory/.EcuRep-Lenovo_*") ) { print $file,"\n"; } } my $list_file = shift @ARGV; die "list_file is missing - Usage: $0 list_file\n" unless $list_file; open(F,"<",$list_file) || die "can not open $list_file: $!\n"; while (my $line = <F> ) { chomp $line; my $dir = dirname $line; remove_files_in_empty_directories($dir); }
/ecurep/hw/7/7042/21/EC/21EC3EC/.EcuRep-Lenovo_outofscope /ecurep/hw/7/7042/21/EC/21EC41C/.EcuRep-Lenovo_outofscope /ecurep/hw/7/7042/21/EC/21EC4DC/.EcuRep-Lenovo_outofscope
/ecurep/hw/7/7042/21/EC/21EC4DC/.EcuRep-Lenovo_outofscope
perl test_perl test2 No Output (as expected)/ecurep/hw/7/7042/21/EC/21EC3EC/.EcuRep-Lenovo_outofscope /ecurep/hw/7/7042/21/EC/21EC41C/.EcuRep-Lenovo_outofscope
I am working with perl on AIX here. I have tested with perl 5.20 on AIX7.2 and perl 5.8.8 on AIX6.1. The behaviour is the same.drwxr-s--- 4 root swsupt 512 Apr 08 04:53 21EC3EC drwxr-s--- 4 root swsupt 512 Apr 08 05:24 21EC41C drwxr-s--- 5 root swsupt 512 Apr 11 12:12 21EC4DC [1:root@itcaix23:]/ecurep/tmp/perl_test # ls -l /ecurep/hw/7/7042/21/E +C/21EC41C total 0 -rw-r--r-- 1 root swsupt 25 Jun 24 2016 .EcuRep-Leno +vo_outofscope drwxr-s--- 2 root swsupt 512 Mar 31 09:06 2017-03-31 drwxr-s--- 2 root swsupt 512 Apr 07 09:05 2017-04-07 [1:root@itcaix23:]/ecurep/tmp/perl_test # ls -l /ecurep/hw/7/7042/21/E +C/21EC4DC total 0 -rw------- 1 root swsupt 29 Apr 11 12:12 .EcuRep-Leno +vo_outofscope drwxr-s--- 2 root swsupt 512 Mar 28 09:48 2017-03-28 drwxr-s--- 2 root swsupt 512 Apr 04 09:49 2017-04-04 drwxr-s--- 2 root swsupt 512 Apr 11 09:48 2017-04-11 [1:root@itcaix23:]/ecurep/tmp/perl_test # ls -l /ecurep/hw/7/7042/21/E +C/21EC3EC total 0 -rw-r--r-- 1 root swsupt 25 Nov 04 05:26 .EcuRep-Leno +vo_outofscope drwxr-s--- 2 root swsupt 512 Mar 31 06:26 2017-03-31 drwxr-s--- 2 root swsupt 512 Apr 07 06:26 2017-04-07
I am not shure if I am misusing glob here of if there is a problem with my perl-version. Can someone help me understanding what is going on?# makes no difference return if glob "'${directory}/*'"; # with this construct it works! my @files = glob("$directory/*"); return if scalar @files; # doesn't work either - prints "hi hi <directory-name> if ( glob("$directory/*") ) { print "hi\n"; return; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Strange behaviour when using glob in if condition
by haukex (Archbishop) on Apr 11, 2017 at 18:02 UTC | |
by LanX (Saint) on Apr 11, 2017 at 21:25 UTC | |
Re: Strange behaviour when using glob in if condition
by vrk (Chaplain) on Apr 11, 2017 at 13:55 UTC | |
Re: Strange behaviour when using glob in if condition
by haukex (Archbishop) on Apr 11, 2017 at 13:31 UTC |