Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
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: (6)
As of 2014-12-21 04:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (103 votes), past polls