To elaborate (because this foxed me, I thought <> must have different behaviour when passed an array), as far as I can tell, the reason this appears to work is a result of:
- glob("pattern") returns "pattern" if no files match the pattern (this includes patterns which no metacharacters, such as 'blue');
- In a scalar context <pattern> is magic - it keeps state and returns each successive value of glob("pattern"). For example, create files touch tt1 tt2 tt3 and then run:
print scalar <tt?>, "\n" for 1..3;
# prints tt1, tt2 and tt3
Note that (like the flipflop operator) each seperate instance of <pattern> appears to keep its own internal state.
print scalar <tt?>, "\n";
print scalar <tt?>, "\n";
print scalar <tt?>, "\n";
# prints tt1, tt1, tt1
And to drive the point home, fun with closures:
my $s = sub { return scalar <tt?>; };
print $s->(), "\n";
print $s->(), "\n";
print $s->(), "\n";
# prints tt1, tt2, tt3
So...this will "work" provided none of the array elements is a string which both contains a glob metacharacter and matches a file as a glob. (If the array elt doesn't contain any such chars, it doesn't matter if it matches or not - you'll get back the pattern).
| [reply] [d/l] [select] |