> > I've got an array returned from Google's API and I need to get the > > data out of it. The best I can do right now is: > > > > ARRAY(0x8262e088) > > What you got is an reference to an array (an arrayref); printed out it looks > linke something above. > > To access the array referenced to it must be dereferenced. > > Documentation: perldoc perlref > > Code example: > > use strict; > use warnings; > > my $arrayref=[qw(1 2 3 4)]; # an arrayref > > print "arrayref printed: ", $arrayref, "\n"; # what you accessed > print "array referenced printed: ", @$arrayref, "\n"; # what you wanted to > > my $second_value=$arrayref->[1]; # extract a value > print "second value: ", $second_value "\n"; > > # this prints > > arrayref printed: ARRAY(0x814ac88) > array referenced printed: 1234 > second value: 2
Thanks guys, I've almost got it. I need to save the title and URL of each result in the array to a different "scratch" variable so I can use it outside of the script. The following works great, but of course it only saves the last set of results from the loop. foreach my $result (@{$results->{resultElements}}) { $Scratch->{google_results_title} = $result->{title}, $Scratch->{google_results_url} = $result->{URL}; } What I need is a way to save each title and URL to a different scratch variable like this: $Scratch->{google_results_title_1} = $results->{resultElements}->[1]->{title}, $Scratch->{google_results_url_1} = $results->{resultElements}->[1]->{url}; $Scratch->{google_results_title_2} = $results->{resultElements}->[2]->{title}, $Scratch->{google_results_url_2} = $results->{resultElements}->[2]->{url}; but I need the right syntax. How would that go? If you're curious about scratch variables, it's an Interchange convention. http://www.icdevgroup.org - Grant -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>