Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Different Type of Hashes

by Khen1950fx (Canon)
on May 07, 2012 at 09:30 UTC ( [id://969229]=note: print w/replies, xml ) Need Help??


in reply to Different Type of Hashes

#2 is the correct way to initialize the hash with an even-sized list. #1 and #3---the brackets are in effect creating a reference which isn't what you want.

Replies are listed 'Best First'.
Re^2: Different Type of Hashes
by johngg (Canon) on May 07, 2012 at 10:51 UTC

    Neither, I think, is #2!

    knoppix@Microknoppix:~$ perl -Mstrict -MData::Dumper -wE ' > my %h = ( > ( 1 => q{j}, 2 => q{b} ), > ( 1 => q{p}, 2 => q{b} ), > ); > print Data::Dumper->Dumpxs( [ \ %h ], [ qw{ *h } ] );' %h = ( '1' => 'p', '2' => 'b' ); knoppix@Microknoppix:~$

    It is not clear from the three attempts what the OP desires. If a HoH is the aim then there should be a key with a value of the inner hash reference.

    knoppix@Microknoppix:~$ perl -Mstrict -MData::Dumper -wE ' > my %h = ( > k1 => { 1 => q{j}, 2 => q{b} }, > k2 => { 1 => q{p}, 2 => q{b} }, > ); > print Data::Dumper->Dumpxs( [ \ %h ], [ qw{ *h } ] );' %h = ( 'k2' => { '1' => 'p', '2' => 'b' }, 'k1' => { '1' => 'j', '2' => 'b' } ); knoppix@Microknoppix:~$

    An AoH fits the OP's data best perhaps?

    knoppix@Microknoppix:~$ perl -Mstrict -MData::Dumper -wE ' > my @a = ( > { 1 => q{j}, 2 => q{b} }, > { 1 => q{p}, 2 => q{b} }, > ); > print Data::Dumper->Dumpxs( [ \ @a ], [ qw{ *a } ] );' @a = ( { '1' => 'j', '2' => 'b' }, { '1' => 'p', '2' => 'b' } ); knoppix@Microknoppix:~$

    It would be useful if the OP could clarify their requirement.

    Cheers,

    JohnGG

Log In?
Username:
Password:

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

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

    No recent polls found