Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
This code appears to work given that the output is:#!/usr/bin/perl use strict; use warnings; use constant { FOO => 'foo', BAR => 'bar' }; my %mapping = ( @{[FOO]} => 0, @{[BAR]} => 1 ); for my $k (keys %mapping) { print "$k\t$mapping{$k}\n"; }
I understand that constants are implemented as subroutines which return the value assigned, but I don't understand the syntax. What is the @{[...]} syntax doing? I know that it isn't an array, and ultimately the subroutine has to be called before constructing the reference (?) into the hash, but I'm only guessing. Can you elucidate what the syntax is really specifying to the Perl interpreter?bar 1 foo 0
Thanks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
•Re: explanation of constant syntax?
by merlyn (Sage) on Mar 20, 2004 at 02:29 UTC | |
by meonkeys (Chaplain) on Mar 20, 2004 at 17:57 UTC | |
by merlyn (Sage) on Mar 20, 2004 at 18:22 UTC | |
|
Re: explanation of constant syntax? ()
by tye (Sage) on Mar 20, 2004 at 06:03 UTC | |
by bart (Canon) on Mar 20, 2004 at 18:25 UTC | |
by tye (Sage) on Mar 20, 2004 at 18:46 UTC | |
by Aristotle (Chancellor) on Mar 20, 2004 at 19:00 UTC | |
by tye (Sage) on Mar 21, 2004 at 04:45 UTC | |
|