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

Retrieving items from an array of hashes

Status
Not open for further replies.

tobhut

Programmer
Feb 27, 2008
1
GB
Hello! Hope someone can help! I'm having a nightmare navigating an array of hashes. I'm using the Perl Twitter Module - . Running this script...

#!/usr/bin/perl

use Net::Twitter;
use Data::Dumper;

print "Content-type: text/plain\n\n";

my $twit = Net::Twitter->new(username=>"username", password=>"password" );
$result = $twit->replies();

print Dumper($result);

I get:

$VAR1 = [
{
'source' => 'web',
'truncated' => bless( do{\(my $o = 0)}, 'JSON::XS::Boolean' ),
'created_at' => 'Thu Feb 21 02:27:32 +0000 2008',
'text' => 'Test Text',
'user' => {
'location' => undef,
'profile_image_url' => ' 'protected' => $VAR1->[0]{'truncated'},
'name' => 'myname',
'description' => undef,
'url' => undef,
'id' => 123456,
'screen_name' => 'myscreenname'
},
'id' => 123123123
},
{
'source' => 'web',
'truncated' => $VAR1->[0]{'truncated'},
'created_at' => 'Thu Feb 21 01:18:55 +0000 2008',
'text' => 'Test Text',
'user' => {
'location' => undef,
'profile_image_url' => ' 'protected' => $VAR1->[0]{'truncated'},
'name' => 'myname',
'description' => undef,
'url' => undef,
'id' => 123456,
'screen_name' => 'myscreenname'
},
'id' => 123123123
},
]

I have no idea how to parse this, I can't even pull any items out. Should by $result even be a scalar? Please please help!

Really appreciate it,
Stuart
 
It looks like it's returning a reference to an array.

So
Code:
$result->[0]->{created_at}
would equal 'Thu Feb 21 02:27:32 +0000 2008'.

This means:
[0] means first element in the array
{created_at} hash entry with key of created_at

Check out the perl man page for perlreftut

On the web, it's at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top