Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Not meaning to add values to a hash

by Athanasius (Archbishop)
on Dec 22, 2012 at 16:29 UTC ( [id://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,

Log In?
Username:
Password:

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

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

    No recent polls found