There are two forms of Perl filename wildcard command: <> and glob. But I found there is difference between the effect of these two forms:
I want to retrieve all the files with similar names, using following code:
my @files = <"rawdata/*_${term}_*.csv">; #(1)
and another format:
my @files = glob "rawdata/*_${term}_*.csv"; #(2)
I expect to get the same result using these two codes. But there is difference: if the $term is a string without spaces (or to say, one word), then (2) works well, but (1) doesn’t work; if the $term is a string with spaces (or to say, several words), then (1) works well, (2) doesn’t work.
Is there any difference between these two expressions?
Thanks a lot.
<SomeStuff>is equivalent toglob "SomeStuff"(apart from all the ambiguities with<>also being used for reading from file handles — seeperldoc perlopand look forI/O Operatorsthere). Therefore your examples aren’t equivalent. You should useinstead.
However, as to why space in the pattern makes a difference:
perldoc -f globtells the story. The normalglob(and therefore<>which is implemented viaglob) treat whitespace as a pattern separator. The documentation also mentionsFile::Globand its functionbsd_globwhich does not treat spaces as pattern separators. Therefore consider using this instead:Possible output with some files I just created: