Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Complicated Hash Construction.

by MarkM (Curate)
on Dec 29, 2002 at 08:14 UTC ( #222884=note: print w/ replies, xml ) Need Help??

in reply to Complicated Hash Construction.

The code:

my @hash{@keyarray} = @valuearray;

Should be understood as:

my($hash{$keyarray[0]}, $hash{$keyarray[1]}, ...) = @valuearray;

Once this is understood, it should be easier to see why Perl considers the expression to be a syntax error. Perl does not know what my($hash{$key}); means. The exact error is `Can't declare hash slice in "my" at ...'

For an interesting comparison, consider the following similar-looking code:

local @hash{@keyarray} = @valuearray;

This code actually works, because local($hash{$key}); is perfectly valid and means 'override the value of $hash{$key} until this block completes'.

Comment on Re: Complicated Hash Construction.
Select or Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2015-10-09 06:49 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (234 votes), past polls