> > > > 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?
> [...]
> 
> > 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.
> 
> Here a possibility with a counter variable used in the key name:
> 
> my $cnt=1;
> foreach my $result (@{$results->{resultElements}}) {
>  $Scratch->{'google_results_title_'.$cnt} = $result->{title},
>  $Scratch->{'google_results_url_'.$cnt} = $result->{URL};
>  $cnt++;
> }

This was just what I needed.  Thanks a lot to everybody.

By the way, I highly recommend Interchange to everyone.  If you know
Perl, you probably won't even have the learning curve problems. 
Interchange is really just another layer on top of lower level stuff,
but don't you ever want to build yourself one of those?

- 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