Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2015-07-03 20:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (56 votes), past polls