Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: Can a single key have different value assigned to it

by mangrove (Novice)
on Apr 19, 2012 at 07:11 UTC ( #965880=note: print w/ replies, xml ) Need Help??


in reply to Re: Can a single key have different value assigned to it
in thread Can a single key have different value assigned to it

Thanks the very first one worked. I was just trying to understand how it was working. So when we do array of hash the each new indices of array will have new key and value that way we avoid overwriting of same key value right?


Comment on Re^2: Can a single key have different value assigned to it
Re^3: Can a single key have different value assigned to it
by Lady_Aleena (Deacon) on Apr 19, 2012 at 07:21 UTC

    You are correct. If you dump the data, you will see all of your data in an array of hashes.

    use Data::Dumper; print Dumper(\@information);
    Have a cookie and a very nice day!
    Lady Aleena
Re^3: Can a single key have different value assigned to it
by Anonymous Monk on Apr 19, 2012 at 07:24 UTC

    It's a hash of arrays

    %info is a hash

    $info{lastnames} is an array reference

    To take a page out of Basic debugging checklist tutorial

    use Data::Dump; dd { lastnames => [ qw/ ro sham bo / ] }; __END__ { lastnames => ["ro", "sham", "bo"] }

    Hmm, lets try that again

    use Data::Dump; my %info; push @{ $info{lastnames} }, 'ro'; push @{ $info{lastnames} }, 'sham'; push @{ $info{lastnames} }, 'bo'; dd \%info; __END__ { lastnames => ["ro", "sham", "bo"] }

    Thats better. Last demo

    use Data::Dump; my %info; $info{lastnames}[0] = 'ro'; $info{lastnames}[1] = 'sham'; $info{lastnames}[2] = 'bo'; dd \%info; __END__ { lastnames => ["ro", "sham", "bo"] }

    Any time you're wondering about something , write yourself a little program like these three :) hashofarrays.01.pl, hashofarrays.02.pl, hashofarrays.03.pl

    Does a hash of arrays make sense for your use case, maybe :) maybe @records is a better fit, I can't tell yet

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2014-12-20 16:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (96 votes), past polls