CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Array of Hashes

 



perllearner
Novice

Oct 14, 2009, 7:04 AM

Post #1 of 3 (531 views)
Array of Hashes Can't Post

Hi,

I have some piece of code below,

@array = (1,2,3,{"perl"=>1,"unix"=>2});

now, I want to print the entire contents of array( including the values of the hash)

How is it possible?


FishMonger
Veteran / Moderator

Oct 14, 2009, 8:18 AM

Post #2 of 3 (529 views)
Re: [perllearner] Array of Hashes [In reply to] Can't Post

Loop through the array elements checking its reftype and then use the proper construct to output that data type.

Check out the reftype function in the Scalar::Util module.
http://search.cpan.org/~gbarr/Scalar-List-Utils-1.21/lib/Scalar/Util.pm

Then work up some code and post back with that code when you run into a problem that you can't figure out.


shawnhcorey
Enthusiast


Oct 14, 2009, 8:57 AM

Post #3 of 3 (526 views)
Re: [perllearner] Array of Hashes [In reply to] Can't Post


In Reply To
Hi,

I have some piece of code below,

@array = (1,2,3,{"perl"=>1,"unix"=>2});

now, I want to print the entire contents of array( including the values of the hash)

How is it possible?


Yes, use Data::Dumper. It's a standard module that comes with Perl. See `perldoc Data::Dumper` http://perldoc.perl.org/Data/Dumper.html

__END__

I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives