Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Using a hash with the @ sigil

by choroba (Cardinal)
on Jul 24, 2015 at 23:41 UTC ( [id://1136248]=note: print w/replies, xml ) Need Help??


in reply to Using a hash with the @ sigil

It's so called "hash slice".
use warnings; use strict; use Data::Dumper; my @arr = qw( a b c ); my %h; @h{@arr} = (3, 4, 5); # @hash{keys} = values print Dumper(\%h); __END__ Output: $VAR1 = { 'c' => 5, 'b' => 4, 'a' => 3 };
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: Using a hash with the @ sigil
by 1nickt (Canon) on Jul 25, 2015 at 01:05 UTC

    Thanks choroba and all the other monks who replied...

    The way forward always starts with a minimal test.
Re^2: Using a hash with the @ sigil
by Anonymous Monk on Jul 25, 2015 at 14:25 UTC
    Hash slices are useful, but assigning a scalar to them is less useful. Perl could warn in that case, but I don't know that it should.
    @hash{@array} = 'foo'; # converted to a 1-element list @hash{@array} = ('foo'); # equivalent @hash{@array} = ('foo', undef, undef); # equivalent @hash{@array} = ('foo', 'foo', 'foo'); # arguably should be equivalent

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-25 23:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found