my $location_array_ref; if (ref($location_ref) eq 'ARRAY') { $location_array_ref = $location_ref; } else { $location_array_ref = [ $location_ref ]; } #### expression1 ? expression2 : expression3 #### foreach my $e (@{$getToysResults->{Toys}{Toy}}) { my $location_ref = $e->{ToyLocations}{ToyLocation}; my $ref_type = ref $location_ref; my $location_array_ref = $ref_type eq 'ARRAY' ? $location_ref : $ref_type eq 'HASH' ? [ $location_ref ] : $ref_type eq 'SCALAR' ? [ { locationName => $$location_ref } ] : $ref_type eq '' ? [ { locationName => $location_ref } ] : undef; die 'Data corrupt' unless defined $location_array_ref; for my $location_array_hash_ref (@$location_array_ref) { print $location_array_hash_ref->{locationName}, "\n"; } } #### #!/usr/bin/env perl use strict; use warnings; my $default = 'default'; my $default_loc_name = "SCALAR:$default"; my $default_loc_name_ref = \$default_loc_name; my $getToysResults = { 'Toys' => bless( { 'Toy' => [ bless( { 'ToyLocations' => bless( { 'ToyLocation' => sub { 1 } }, 'ArrayOfToyLocation' ), }, 'corrupt' ), bless( { 'ToyLocations' => bless( { 'ToyLocation' => $default }, 'ArrayOfToyLocation' ), }, 'Scalar' ), bless( { 'ToyLocations' => bless( { 'ToyLocation' => $default_loc_name_ref }, 'ArrayOfToyLocation' ), }, 'Scalarref' ), bless( { 'ToyLocations' => bless( { 'ToyLocation' => { 'toyQuantity' => '2', 'locationName' => 'HASH:toybox' } }, 'ArrayOfToyLocation' ), 'color' => 'brown', 'toyName' => 'bear', 'size' => 'large' }, 'Stuffed' ), bless( { 'ToyLocations' => bless( { 'ToyLocation' => [ { 'toyQuantity' => '1', 'locationName' => 'ARRAY:toybox' }, { 'toyQuantity' => '4', 'locationName' => 'ARRAY:shelf' } ] }, 'ArrayOfToyLocation' ), 'color' => 'none', 'toyName' => 'Sorry', 'size' => 'medium' }, 'Board' ) ] }, 'ArrayOfToy' ) }; foreach my $e (@{$getToysResults->{Toys}{Toy}}) { my $location_ref = $e->{ToyLocations}{ToyLocation}; my $ref_type = ref $location_ref; my $location_array_ref = $ref_type eq 'ARRAY' ? $location_ref : $ref_type eq 'HASH' ? [ $location_ref ] : $ref_type eq 'SCALAR' ? [ { locationName => $$location_ref } ] : $ref_type eq '' ? [ { locationName => $location_ref } ] : undef; warn 'Data corrupt' unless defined $location_array_ref; for my $location_array_hash_ref (@$location_array_ref) { print $location_array_hash_ref->{locationName}, "\n"; } } #### $ pm_parse_soap_ref.pl Data corrupt at ./pm_parse_soap_ref.pl line 69. default SCALAR:default HASH:toybox ARRAY:toybox ARRAY:shelf