How does glob return "filenames" that are not there?
This answer indicates that glob can sometimes return filenames that don't exist.
@deck = glob "{A,K,Q,J,10,9,8,7,6,5,4,3,2}{\x{2660},\x{2665},\x{2666},\x{2663}}";
However, this code returns an empty list when I run it.
What am I missing?
This launch was done from the command line using -e, on Windows XP, with the ActiveState Perl version 5.005_02. Executing from a saved script on the same computer gives the same results.
Working with -e on Windows XP with ActiveState Perl v5.8.7 returns an array.
source to share
This works well for me - i.e. creates a deck of cards, I am using perl 5.8.8.
But. Using glob for this seems odd - I mean - of course it is possible, but glob is a file matching tool that does not guarantee actual file validation, but no one says it will not be file compatible in the future!
I would definitely go with a different approach. For example, for example:
my @cards = qw( A K Q J 10 9 8 7 6 5 4 3 2 );
my @colors = ( "\x{2660}", "\x{2665}", "\x{2666}", "\x{2663}" );
my @deck = map {
my $card = $_;
map { "$card$_" } @colors
} @cards;
Or if you find {map} too cryptic:
my @deck;
for my $card ( @cards ) {
for my $color ( @colors ) {
push @deck, "$card$color";
}
}