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

Re: Using a hash with the @ sigil

by AnomalousMonk (Archbishop)
on Jul 24, 2015 at 23:50 UTC ( [id://1136251]=note: print w/replies, xml ) Need Help??


in reply to Using a hash with the @ sigil

Why doesn't Perl have a warning for the [@hash{@array} = 'foo'] case?

I would say because an empty hash slice assignment | index list is a perfectly valid thing. It's equivalent to
    $hash{$_} = 'foo' for @array;
which also does not (and should not) warn.

c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my %hash = qw(a 1 b 2); my @array; @hash{@array} = 'foo'; dd \%hash; ;; $hash{$_} = 'foo' for @array; dd \%hash; " { a => 1, b => 2 } { a => 1, b => 2 }


Give a man a fish:  <%-(-(-(-<

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2024-05-29 12:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found