Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello, most erudite monks,

I'm just a beginner, so this is probably a dumb question. I'm trying to print out each value of an array. The problem is, the array is inside a hash called %results. To get to that array I use $results{$key}.
for each $line ($results{$key}) { print "\t$line\n"; }
When I try to run the program, it prints out something like this: ARRAY(0x1aada0c)

What am I doing wrong?

Replies are listed 'Best First'.
Re: Easy question
by jettero (Monsignor) on Jul 29, 2009 at 18:09 UTC
Re: Easy question
by lostjimmy (Chaplain) on Jul 29, 2009 at 18:46 UTC
    In addition to what jettero already said for printing a whole array, you still might be interested to know how to use said array in a for loop. Just a simple change to your code does the trick:
    foreach $line (@{$results{$key}}) { print "\t$line\n"; }
Re: Easy question
by mzedeler (Pilgrim) on Jul 29, 2009 at 19:57 UTC

    In addition to the above, if you are completely lost, not knowing the exact structure of some variable, say $x, you can dump it like so:

    use warnings; use strict; use Data::Dumper; print Dumper $x;