#!/usr/bin/perl
use warnings;
use strict;
my $mixed = [
'scalar', ['a', 'B', ['c', 'd'], 'e'],
{And=>{'A'=>'A'}}, \'a scalar ref'
];
print_structure($mixed);
sub print_structure {
my ($data) = @_;
foreach (ref $data) {
/^$/ and print($data,"\n"), next;
/^SCALAR/ and print('-> ', $$data, "\n"), next;
/^HASH/ and do {
print "\n";
foreach my $key (keys %{$data}) {
print "$key => ";
print_structure ($data->{$key});
}
next;
};
/^ARRAY/ and do {
print "\n";
for my $elc (0..$#{$data}) {
print "[$elc] : ";
print_structure ($data->[$elc]);
}
next;
};
print "?$data?";
}
}
|