Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: symbolic reference & loading hashes

by neosamuri (Friar)
on Jul 20, 2007 at 16:01 UTC ( [id://627820]=note: print w/replies, xml ) Need Help??


in reply to symbolic reference & loading hashes

I believe what you are looking for is:

@{@keys} = @values;

${...} is scalar, but the return you want is an array @rld is the keys in the package hash. @{...} takes keys and returns values. ${...} takes a key and returns a value.

Replies are listed 'Best First'.
Re^2: symbolic reference & loading hashes
by ikegami (Patriarch) on Jul 20, 2007 at 16:39 UTC

    Nope, that will evaluate @keys in scalar context in order to deref the value. Perl doesn't provide any direct means of setting multiple referenced values at once, so a loop is needed.

    for my $i (0..$#keys) { ${$keys[$i]} = $values[$i]; }

    Alternatively,

    use List::MoreUtils qw( pairwise ); pairwise { ${$a} = $b } @keys, @values;

    Of course, hashes are better than symbolic references.

    @hash{@keys} = @values;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (2)
As of 2024-04-26 00:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found