BradV has asked for the wisdom of the Perl Monks concerning the following question:
I'm writing some code to parse some xml files. One element could either have a single value or an array of values. I have:
if ( ref($xmlcollection->{phone}->{callTo}) eq "ARRAY" ) { printf( "Call To:" ); foreach ($xmlcollection->{phone}->{callTo}) { print "$_\n"; } } else { printf( "Call To: %s\n", $xmlcollection->{phone}->{callTo}); }
It just prints the array reference. If I add:
printf( "%s\n",$xmlcollection->{phone}->{callTo}[0]); printf( "%s\n", $xmlcollection->{phone}->{callTo}[1]);
it prints the correct values. The problem is I don't always know how many elements will be in the array. How do I correctly reference the array element of the hash in order to print out all of the values?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: What is correct way to reference?
by haukex (Archbishop) on May 22, 2017 at 17:51 UTC | |
|
Re: What is correct way to reference?
by Eily (Monsignor) on May 22, 2017 at 17:19 UTC | |
|
Re: What is correct way to reference?
by Your Mother (Archbishop) on May 22, 2017 at 17:30 UTC | |
|
Re: What is correct way to reference?
by BillKSmith (Monsignor) on May 22, 2017 at 20:27 UTC | |
by BradV (Sexton) on May 23, 2017 at 13:10 UTC | |
|
Re: What is correct way to reference?
by shmem (Chancellor) on May 22, 2017 at 17:43 UTC | |
|
Re: What is correct way to reference?
by 1nickt (Canon) on May 22, 2017 at 18:41 UTC | |
by AnomalousMonk (Archbishop) on May 22, 2017 at 20:48 UTC | |
by 1nickt (Canon) on May 22, 2017 at 21:30 UTC |