![]() |
|
We don't bite newbies here... much | |
PerlMonks |
Strange behaviour when using glob in if conditionby yulivee07 (Sexton) |
on Apr 11, 2017 at 13:21 UTC ( #1187638=perlquestion: print w/replies, xml ) | Need Help?? |
yulivee07 has asked for the wisdom of the Perl Monks concerning the following question:
Hi fellow perlmonks, I noticed a strange behaviour when using glob to expand filenames. I try to identify directories which contain nothing besides one special sort of file. I noticed that the return condition of my script failed to execute, even if glob returned something. I pass this script a file containing a list of directories (filename is test):
I call the script like this: perl test_perl test Output:
This is kinda unexpected, as all three directories contain other directories. When I step through with the debugger, I can evaluate the glob with x, and it returns a list of directories every single time. If I evaluate x scalar glob("$directory/*") it also evaluates to the first entry from the list every time. But in case if the last pathname it steps further into the function anyway instead of executing my return statement. I cannot get my head wrapped around this - what is happening here? Further testing of the problem: If I delete the first line of the testfile, thereby removing the first directory from the list of directories to be one shorter, it works. test2: perl test_perl test2 No Output (as expected) File Permissions to the directories: 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. I tried the following variations on the code (just substituting the problematic part): 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? Kind regards, Yulivee
Back to
Seekers of Perl Wisdom
|
|