Leser: 3
4 Einträge, 1 Seite |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my $a;
$a->[0]->{'a'}="000aaa";
$a->[0]->{'b'}="000bbb";
$a->[1]->{'a'}="111aaa";
$a->[1]->{'b'}="111bbb";
$a->[2]->{'q'}->[0]="qqqqq";
print Dumper($a);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$VAR1 = [
{
'a' => '000aaa',
'b' => '000bbb'
},
{
'a' => '111aaa',
'b' => '111bbb'
},
{
'q' => [
'qqqqq'
]
}
];
1
2
3
4
5
$a->[0]->{'a'}="000aaa";
$a->[0]->{'b'}="000bbb";
$a->[1]->{'a'}="111aaa";
$a->[1]->{'b'}="111bbb";
$a->[2]->{'q'}->[0]="qqqqq";
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
sub nodes {
my ($name, $ref, $path) = @_;
if (ref $ref eq "ARRAY") {
nodes($name, $ref->[$_], [@$path, ["array", $_]]) for 0..$#$ref;
}
elsif (ref $ref eq "HASH") {
nodes($name, $ref->{$_}, [@$path, ["hash",$_]]) for sort keys %$ref;
}
else {
print $name;
for my $p (@$path) {
print $p->[0] eq "array" ? "->[$p->[1]]" : "->{$p->[1]}"
}
print qq/ = "$ref";\n/;
}
}
nodes(q/$a/, $a, []);
4 Einträge, 1 Seite |