XML results questions

XML results questions

am 22.01.2008 22:47:02 von Sharon

I'm retrieving an XML result from a website and the the result changes
according to the number of Items returned.
if only one item returned the XML use a hash to hold the name and
value, however if more then one Item was returned it uses an Array to
hold all the results.
I'm trying to right a foreach statement to extract all the information
and when I get one Item I get an error that this is not an Aray
referance (which is obvius).
does anyone have a seggestion, how can I find if the results are in an
array or a hash?

Thanks
Arik

Re: XML results questions

am 22.01.2008 22:55:37 von smallpond

On Jan 22, 4:47 pm, sha...@blue-linedesign.com wrote:
> I'm retrieving an XML result from a website and the the result changes
> according to the number of Items returned.
> if only one item returned the XML use a hash to hold the name and
> value, however if more then one Item was returned it uses an Array to
> hold all the results.
> I'm trying to right a foreach statement to extract all the information
> and when I get one Item I get an error that this is not an Aray
> referance (which is obvius).
> does anyone have a seggestion, how can I find if the results are in an
> array or a hash?
>
> Thanks
> Arik


Some subs return either a scalar or list based on context
which may be the problem you are having. If you posted
the code which is returning the morphing value and the
way that you are calling it then someone might be able
to help you.
--S

Re: XML results questions

am 22.01.2008 23:02:45 von it_says_BALLS_on_your forehead

On Jan 22, 4:47=A0pm, sha...@blue-linedesign.com wrote:
> I'm retrieving an XML result from a website and the the result changes
> according to the number of Items returned.
> if only one item returned the XML use a hash to hold the name and
> value, however if more then one Item was returned it uses an Array to
> hold all the results.
> I'm trying to right a foreach statement to extract all the information
> and when I get one Item I get an error that this is not an Aray
> referance (which is obvius).
> does anyone have a seggestion, how can I find if the results are in an
> array or a hash?

Since you're dealing with references, this is easy.

There's a built-in function (ref) which does precisely this.
if ( ref($r) eq 'HASH' ) {
print "r is a reference to a hash.\n";
}
else if ( ref($r) eq 'ARRAY' ) {
print "\$r is an array ref.\n";
}

HTH

Re: XML results questions

am 22.01.2008 23:07:49 von glex_no-spam

nolo contendere wrote:
> On Jan 22, 4:47 pm, sha...@blue-linedesign.com wrote:
>> I'm retrieving an XML result from a website and the the result changes
>> according to the number of Items returned.
>> if only one item returned the XML use a hash to hold the name and
>> value, however if more then one Item was returned it uses an Array to
>> hold all the results.
>> I'm trying to right a foreach statement to extract all the information
>> and when I get one Item I get an error that this is not an Aray
>> referance (which is obvius).
>> does anyone have a seggestion, how can I find if the results are in an
>> array or a hash?
>
> Since you're dealing with references, this is easy.
>
> There's a built-in function (ref) which does precisely this.
> if ( ref($r) eq 'HASH' ) {
> print "r is a reference to a hash.\n";
> }
> else if ( ref($r) eq 'ARRAY' ) {
> print "\$r is an array ref.\n";
> }

In addition, if you're using XML::Simple, read the documentation for
ForceArray.

Re: XML results questions

am 23.01.2008 05:29:57 von 1usa

sharon@blue-linedesign.com wrote in news:8e07a530-aa04-4db2-a574-
d10442feca48@u10g2000prn.googlegroups.com:

> Subject: XML results questions
....

> how can I find if the results are in an
> array or a hash?

You keep claiming that you have XML questions but your questions always
turn out to be basic language related questions.

You should check out the table of contents of Perl documentation installed
on your computer and read at least perlsyn, perldata, perlvar and perlfaq
for starters.

Then, you should take a look at perldsc and perlref at a minimum.

Sinan

--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
clpmisc guidelines:

Re: XML results questions

am 23.01.2008 05:55:28 von Sharon

On Jan 22, 2:07 pm, "J. Gleixner"
wrote:
> nolo contendere wrote:
> > On Jan 22, 4:47 pm, sha...@blue-linedesign.com wrote:
> >> I'm retrieving an XML result from a website and the the result changes
> >> according to the number of Items returned.
> >> if only one item returned the XML use a hash to hold the name and
> >> value, however if more then one Item was returned it uses an Array to
> >> hold all the results.
> >> I'm trying to right a foreach statement to extract all the information
> >> and when I get one Item I get an error that this is not an Aray
> >> referance (which is obvius).
> >> does anyone have a seggestion, how can I find if the results are in an
> >> array or a hash?
>
> > Since you're dealing with references, this is easy.
>
> > There's a built-in function (ref) which does precisely this.
> > if ( ref($r) eq 'HASH' ) {
> > print "r is a reference to a hash.\n";
> > }
> > else if ( ref($r) eq 'ARRAY' ) {
> > print "\$r is an array ref.\n";
> > }
>
> In addition, if you're using XML::Simple, read the documentation for
> ForceArray.

Thanks for the tips
I appreciate it

Re: XML results questions

am 23.01.2008 06:02:11 von Sharon

On Jan 22, 8:29 pm, "A. Sinan Unur" <1...@llenroc.ude.invalid> wrote:
> sha...@blue-linedesign.com wrote in news:8e07a530-aa04-4db2-a574-
> d10442fec...@u10g2000prn.googlegroups.com:
>
> > Subject: XML results questions
>
> ...
>
> > how can I find if the results are in an
> > array or a hash?
>
> You keep claiming that you have XML questions but your questions always
> turn out to be basic language related questions.
>
> You should check out the table of contents of Perl documentation installed
> on your computer and read at least perlsyn, perldata, perlvar and perlfaq
> for starters.
>
> Then, you should take a look at perldsc and perlref at a minimum.
>
> Sinan
>
> --
> A. Sinan Unur <1...@llenroc.ude.invalid>
> (remove .invalid and reverse each component for email address)
> clpmisc guidelines:
Thanks for pointing me out to the documentation I'll definitely look
this up, I sure hope though that these suggestions come in good spirit