tptass has asked for the wisdom of the Perl Monks concerning the following question:
Let me preface this with this is actually working code and that I'm simply just looking for a better way to go about doing the follow, really the optimal way of do it.
I basically am reading an xml file and for a given key I'm creating anArray. However, there are cases where the key can have many xml elements in which xmlin returns an Array or the other case where just a single element (a scalar) is returned. Is there any other way to approach this, a better way?
if ( ref($xmlin->{$key}) eq "ARRAY") { @anArray = @{$xmlin->{$key}}; } else { push @anArray, $xmlin->{$key}; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XMLin : Optimal Way to tell the difference between Array vs Scalar
by BrowserUk (Patriarch) on Aug 19, 2008 at 23:48 UTC | |
by tptass (Sexton) on Aug 20, 2008 at 00:11 UTC | |
|
Re: XMLin : Optimal Way to tell the difference between Array vs Scalar
by ysth (Canon) on Aug 20, 2008 at 03:09 UTC | |
by JadeNB (Chaplain) on Aug 20, 2008 at 21:28 UTC | |
|
Re: XMLin : Optimal Way to tell the difference between Array vs Scalar
by grantm (Parson) on Aug 21, 2008 at 01:01 UTC | |
by Jenda (Abbot) on Aug 21, 2008 at 19:24 UTC |