Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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'.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://222884]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2017-08-23 06:41 GMT
Find Nodes?
    Voting Booth?
    Who is your favorite scientist and why?

    Results (347 votes). Check out past polls.