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

Re: Not meaning to add values to a hash

by Athanasius (Chancellor)
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,

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1010027]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2017-11-19 18:39 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (282 votes). Check out past polls.