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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array of hashes help required

Status
Not open for further replies.

Buddyholly83

IS-IT--Management
Aug 7, 2005
23
GB
Trying to add hashes to array then loop through and print them off. To add each hash to the array i am using:
Code:
push (@messages,
			{
				messageID => $1,
				originator => $2,
				recipient => $3,
				body => $4,
				receivedAt => $5,
				type => $6
			});

To print the contents i am using:
Code:
my $messageTotal = scalar(@messages);

for(my $i = 0; $i < $messageTotal; $i++)
{
	print $messages[$i]{'messageID'};
}

Not getting any errors but it isn't printing anything out either!!

Thanks in advance :)
 
Your syntax is fine. Are you sure $1, $2, $3 etc are being set correctly. In order for those to be set, you'll need a successful regexp match with at least 6 capturing groups. Are you checking that your regexp matches before adding the hash to @messages?
 
Code:
use strict;
use warnings;
use Data::Dumper;

# your stuff here

print Dumper($messages);
will give you a full indented print out of the contents, which may help.
 
The array was being input the values ok. But because i was passing the array back through several classes, in one of them i referred to the array as a scalar by accident -> this takes the array size and this is why it wasnt being output. The Dumper method is handy - thanks stevexff!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top