in reply to Re: XMLin : Optimal Way to tell the difference between Array vs Scalar
in thread XMLin : Optimal Way to tell the difference between Array vs Scalar
… which, since we're going through the keys in a hash, can be nicely combined with a map:@anArray = ref $xmlin->{$key} ? @{$xmlin->{$key}} : $xmlin->{$key};
(assuming that we want everything from the hash, not just a single entry—which is what I guess the poster wanted, which would explain the strange assignment/push choice).@anArray = map { my $x; ref( $x = $xmlin->{$_} ) eq 'ARRAY' ? @$x : $x + } keys %$xmlin;
|
|---|