Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array in hashes???? 2

Status
Not open for further replies.

isodbaar

Programmer
Joined
Aug 11, 2006
Messages
3
Location
CA
hi Guys,
I have an hash that look like this (debug)

x %myhash
0 'ParentFolder'
1 '//server/folder1/'
2 'myarray'
3 ARRAY(0x1f6dc08)
0 'January'
1 'February'
2 'March'
3 'April'
4 'May'
5 'June'
6 'July'
7 'August'
8 'September'
9 'October'
10 'November'
11 'December'

What I want to do is to print the array in the key 'myarray'.
I am trying
foreach ($myhash{'myarray'}) {
print "$_\n";

}

All I get is ARRAY(0x1a59d28).

Thanks!!!
 
In that case, $_ is a reference to an array.

foreach (@{$myhash{'myarray'}}) {
print "$_\n";
}

That will get you the values of the arrayref.

On this topic though, check out Data::Dumper.

Code:
use Data::Dumper;
print Dumper ($myhash);

Data::Dumper prints out the data structures of hashes and arrays (and references of each)... yours might look like this:

Code:
(
   'ParentFolder' => '//server/folder1',
   'myarray'      => [ # square brackets = arrayref
      'February',
      'March',
      'April',
      'May',
      'June',
      'July',
      'August',
      'September',
      'October',
      'November',
      'December',
   ],
);

Data::Dumper makes it easy to copy/paste your data structure for posts such as this one to Tek-Tips, rather than the way you wrote it out up there.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top