Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: Custom HOA printing

by serf (Chaplain)
on Jan 28, 2006 at 18:45 UTC ( #526192=note: print w/replies, xml ) Need Help??

in reply to Custom HOA printing

As you're just new with hashes of arrays (and presumably other complex data structures) you should find Data::Dumper helps you to A) define data structures in one hit and B) clearly see what your data structure contains:
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %hash; push @{$hash{"3"}}, "apple"; push @{$hash{"2"}}, "pear"; push @{$hash{"5"}}, "orange"; push @{$hash{"3"}}, "grape"; push @{$hash{"2"}}, "icky pineapple"; print Dumper(\%hash), $/;
(note the backslash in front of the % in the print statement) which would give you:
$VAR1 = { '3' => [ 'apple', 'grape' ], '2' => [ 'pear', 'icky pineapple' ], '5' => [ 'orange' ] };
Just change the $VAR1 to %hash and the {} to () and it's done for you :o)
my %hash = ( '3' => [ 'apple', 'grape' ], '2' => [ 'pear', 'icky pineapple' ], '5' => [ 'orange' ] );

Replies are listed 'Best First'.
Re^2: Custom HOA printing
by McDarren (Abbot) on Jan 29, 2006 at 00:37 UTC
    Even easier still if you use Data::Dumper::Simple.

    No need to reference the hash, and the data comes out exactly the same way as it would be defined.


    print Dumper(%hash);
    %hash = ( '3' => [ 'apple', 'grape' ], '2' => [ 'pear', 'icky pineapple' ], '5' => [ 'orange' ] );
    Darren :)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://526192]
[Your Mother]: Dist::Zilla is kind of the nuclear option. I set it up back in the day but it's really targeted at authors who are managing MANY modules and want to automate everything.
[erix]: perlancar should know ;)
[LanX]: see warning
[Your Mother]: Thanks for the warning notice.
[LanX]: :p
[LanX]: confusing sh+t
[Your Mother]: Yes.

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2017-08-18 17:49 GMT
Find Nodes?
    Voting Booth?
    Who is your favorite scientist and why?

    Results (306 votes). Check out past polls.