in reply to Pushing a hashref into an array
Maybe this is it:
ref EXPR ref Returns a non‐empty string if EXPR is a reference
You wrote this:
if ( ref $address eq HASH )HASH doesn't look like a string to me. Here is a proof of concept:
You can toggle the comment to see that the code works for a reference to an array of hashes, as well as a reference to a hash.use strict; use warnings; use 5.010; my %h1 = qw{Addressee David Street Street1}; my %h2 = qw{Addressee Kathy Street Street2}; my $templist; #my $address = [\%h1, \%h2]; my $address = \%h1; if (ref $address eq 'HASH') { $templist = [$address]; }else{ $templist = $address; } foreach my $response ( @ $templist ) { print "name: $response->{Addressee}<br>\n"; print "street: $response->{Street}<br>\n"; } --output:-- name: David<br> street: Street1<br>
|
|---|