Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re^3: Common Perl Idioms

by Eimi Metamorphoumai (Deacon)
on Jul 27, 2004 at 14:55 UTC ( #377756=note: print w/replies, xml ) Need Help??

in reply to Re^2: Common Perl Idioms
in thread Common Perl Idioms

It's creating a hash named %foo using a hash slice built out of the elements in @foo. Then it's assigning to that slice the values 0 to (the number of elements). So if @foo = ('a', 'b', 'c'), you get
@foo{'a', 'b', 'c'} = (0, 1, 2);
which is itself just shorthand for
$foo{'a'} = 0; $foo{'b'} = 1; $foo{'c'} = 2;
(technically, @foo in scalar context returns a value one too large, so we're really mapping to (0,1,2,3), but the odd element gets ignored. It might be more proper to use $#foo there (the index of the last element, instead of the number of elements))

Replies are listed 'Best First'.
Re^4: Common Perl Idioms
by Anonymous Monk on Jul 27, 2004 at 15:09 UTC
    Aaaaaaaah... That was clever. Thanks!

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://377756]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2023-04-01 06:56 GMT
Find Nodes?
    Voting Booth?

    No recent polls found