> > 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?
> 
> Instead of using masses of hash keys of the sort "google_results_title_<n>,
> you should add an additional dimension in the result data structure, e.g.
> $Scratch->{google_results_title}->[1]=..., not
> $Scratch->{google_results_title_1} =...
> 
> But since you only want to collect urls and their title, why not simply use a
> hash for that:
> 
>   foreach my $result (@{$results->{resultElements}}) {
>      $Scratch->{ $result->{URL} } = $result->{title}
>      # Or, if neccessary:
>      #$Scratch->{google_results}->{ $result->{URL} } = $result->{title}
>    }
> 
> Afterwards, you can access the titles with a lookup of the url.

I will need to manipulate the data with Interchange conventions like:

[tmp name="google_results_title_1"]value[/tmp]

and

[scratch name="google_results_title_1"]

and to do that I will need the data in the form of
$Scratch->{google_results_title_1} etc.  What would be the best way to
do that?  Something like my badly formed example would be great.

- Grant

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to