Sprad has asked for the wisdom of the Perl Monks concerning the following question:
I'm writing some code to search through a series of directories and return the name of the one and only .txt file inside each one. For some reason, though, my variable is only being set correctly every othertime the code runs. It doesn't matter if I search the same directory several times, or different ones. It always fails every other time. Here's a simplified version and its output on my system:
@paths = ( "//johnsp/dist", "//johnsp/dist", "//johnsp/dist", "//johnsp/dist", "//johnsp/dist", "//johnsp/dist" ); foreach $dir (@paths) { my $tmp; print "looking in $dir\n"; $tmp = glob("$dir/*.txt"); print glob("$dir/*.txt"), "\n"; print "set tmp to $tmp\n\n"; } Output: looking in //johnsp/dist //johnsp/dist/x86.txt set tmp to //johnsp/dist/x86.txt looking in //johnsp/dist //johnsp/dist/x86.txt set tmp to looking in //johnsp/dist //johnsp/dist/x86.txt set tmp to //johnsp/dist/x86.txt looking in //johnsp/dist //johnsp/dist/x86.txt set tmp to looking in //johnsp/dist //johnsp/dist/x86.txt set tmp to //johnsp/dist/x86.txt looking in //johnsp/dist //johnsp/dist/x86.txt set tmp to
Any guesses?
---
A fair fight is a sign of poor planning.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Glob Misbehavin'
by no_slogan (Deacon) on Jun 14, 2001 at 01:45 UTC | |
by Hofmator (Curate) on Jun 14, 2001 at 17:15 UTC | |
|
Re: Glob Misbehavin'
by LD2 (Curate) on Jun 14, 2001 at 02:13 UTC |