Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Not meaning to add values to a hash

by Athanasius (Canon)
on Dec 22, 2012 at 16:29 UTC ( #1010027=note: print w/ replies, xml ) Need Help??

in reply to Not meaning to add values to a hash

Hello stu96art,

I just want to mention that an initialisation like this:

$flag_assignments{$key}{'starrez'} = $info[ 0]; $flag_assignments{$key}{'abbreviation'} = $info[ 1]; $flag_assignments{$key}{'greek'} = $info[ 2]; $flag_assignments{$key}{'Fall'} = $info[ 3]; $flag_assignments{$key}{'Spring'} = $info[ 4]; $flag_assignments{$key}{'Summer'} = $info[ 5]; $flag_assignments{$key}{'RA-Fall'} = $info[ 6]; $flag_assignments{$key}{'RA-Spring'} = $info[ 7]; $flag_assignments{$key}{'RA-Summer'} = $info[ 8]; $flag_assignments{$key}{'NR-Fall'} = $info[ 9]; $flag_assignments{$key}{'NR-Spring'} = $info[10];

can be written more succinctly using slices:

my @keys = qw(starrez abbreviation greek Fall Spring Summer RA-Fall RA +-Spring RA-Summer NR-Fall NR-Spring); my %flag_assignments; @{ $flag_assignments{$key} }{ @keys } = @info[0 .. 10];

(But flexvault’s suggestions for input validation are the better way to go.)

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Comment on Re: Not meaning to add values to a hash
Select or Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (12)
As of 2015-11-25 14:44 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (679 votes), past polls