in reply to Creating arrays with glob patterns without metacharacters
I find the phrase "If non-empty braces are the only wildcard characters used in the glob" misleading because it makes it sound like there are many wildcard chars to choose from, rather than just * and braces. So that would be "If there is no * in the glob". You also demonstrated that even if there are * in the strings, it can potentially return strings without matching files, because glob("PATTERN_A PATTERN_B") is the same as (glob("PATTERN_A"), glob("PATTERN_B")).
That said, the other difference between glob and qw is interpolation, and quotes. You can't have an element with a space inside qw, but you can in glob. And glob interpolates while qw does not. IIRC ruby has each quoting construct in pairs, interpolating or non interpolating, so you can insert a few variables in a list of words. glob is tricky though, because interpolation is done first, and spaces and quotes in your variables might not do what you want:
use Data::Dump qw( pp ); my $interpolate = "A"; my $trap = "'X Y' Z"; pp qw( $interpolate B 'C D' "E F" $trap); pp < $interpolate B 'C D' "E F" $trap \Q$trap>; __DATA__ ("\$interpolate", "B", "'C", "D'", "\"E", "F\"", "\$trap") ("A", "B", "C D", "E F", "X Y", "Z", "'X\\ Y'\\ Z")
So as a conclusion: qw works exactly like a single quoted string splited on whitespace, but glob can be tricky if braces, *, $, @ or quotes are present in the string. Also qw accepts newlines where glob doesn't.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Why are glob patterns without metacharacters returned
by Lotus1 (Vicar) on Jan 05, 2018 at 16:21 UTC | |
by Eily (Monsignor) on Jan 05, 2018 at 16:24 UTC |