#!/usr/bin/perl -l $dialog->{attributes}{control1} = "abc"; $dialog->{attributes}{control2}[0] = "cde"; $dialog->{attributes}{control2}[1] = "fgh"; for my $control (keys %{ $dialog->{attributes} }) { if (ref $dialog->{attributes}{$control} eq 'ARRAY') { print "@{ $dialog->{attributes}{$control} }"; } else { print $dialog->{attributes}{$control}; } } __END__ abc cde fgh
Or, with an intermediate variable (better readable IMHO):
for my $control (keys %{ $dialog->{attributes} }) { my $val = $dialog->{attributes}{$control}; if (ref $val eq 'ARRAY') { print "@$val"; } else { print $val; } }
And in case there could also be other types (such as hashrefs), you should either test for them, too, or at least write
... } elsif (!ref $val) { print $val; }
for the simple scalar values.
In reply to Re: How to distinguish an array data type from a scalar data type in a complex hash.
by almut
in thread How to distinguish an array data type from a scalar data type in a complex hash.
by Steve_BZ
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |