Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Not meaning to add values to a hash

by Athanasius (Monsignor)
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (9)
As of 2014-10-01 08:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (390 votes), past polls