in reply to Creating arrays with glob patterns without metacharacters

it could cause unintended and confusing side effects

It's of course a matter of opinion, but I do agree with this - it's a neat but somewhat obscure use of glob. It can be useful, as it allows one to generate combinations using just core Perl, without loading e.g. Algorithm::Combinatorics. But all it takes is someone who doesn't know the details ("If non-empty braces are the only wildcard characters used ...") or the interpolation of unchecked variables into the pattern for it to break. Personally, my feeling is that in a one-off script, or with a fixed string plus a comment warning future maintainers, it's ok to use. But if you want to play it safe with respect to future maintainers, I'd avoid it.

As for using <a b c> as a replacement for qw/a b c/, sure it's clever, but IMO it's a silly place to save two characters, and I'd probably recommend against it. Also, I like to use File::Glob ':bsd_glob';, which breaks it:

$ perl -le 'print for <a b c>' a b c $ perl -MFile::Glob=:bsd_glob -le 'print for <a b c>' a b c

Replies are listed 'Best First'.
Re^2: Creating arrays with glob patterns without metacharacters
by Lotus1 (Vicar) on Jan 05, 2018 at 17:09 UTC

    I also use ':bsd_glob'. I could show how if I use a function someone else potentially creates using glob to create an array it would quit working with bsd_glob. Thanks.

    Update: demo code.

    use strict; use warnings; use Data::Dumper; use File::Glob ':bsd_glob'; my @arr1 = get_list1(); print Dumper(\@arr1); my @arr2 = get_list2(); print Dumper(\@arr2); sub get_list1 { return < abc def ghi >; } sub get_list2 { return qw( abc def ghi ); } __DATA__ $VAR1 = [ ' abc def ghi ' ]; $VAR1 = [ 'abc', 'def', 'ghi' ];