Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: My 'perldar' tells me there is a 'better' solution for this list operation

by OfficeLinebacker (Chaplain)
on Nov 03, 2006 at 22:45 UTC ( [id://582189]=note: print w/replies, xml ) Need Help??


in reply to My 'perldar' tells me there is a 'better' solution for this list operation

I see that two responses use a construct like
my %h1; @h1{@l2}=();
I must admit I have seen this before (especially the second line) and I don't understand it. Is it just shorthand for populating a hash's keys collection with the elements of an array? Almost like
keys(%h1)=@l2; ?
Thanks,
T
P.S. I had no other word for that kind of intuitive feel for coding.

_________________________________________________________________________________

I like computer programming because it's like Legos for the mind.

Replies are listed 'Best First'.
Re^2: My 'perldar' tells me there is a 'better' solution for this list operation
by revdiablo (Prior) on Nov 04, 2006 at 01:45 UTC

    A couple of quick examples may make it easier to understand what a hash slice is doing. This code:

    @hash{"one", "two", "three"} = 1 .. 3;

    Is equivalent to:

    ($hash{one}, $hash{two}, $hash{three}) = 1 .. 3;

    And likewise, these are equivalent:

    my @list = @hash{"one", "two", "three"};

    and

    my @list = ($hash{one}, $hash{two}, $hash{three});
Re^2: My 'perldar' tells me there is a 'better' solution for this list operation
by Roy Johnson (Monsignor) on Nov 03, 2006 at 22:53 UTC
    It's a hash slice, for populating multiple values of a hash from a list.

    Caution: Contents may have been coded under pressure.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2024-04-24 10:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found