Thread Data::Dumper, nur etwas anders (3 answers)
Opened by Silicoid at 2007-06-20 01:01

pq
 2007-06-20 01:29
#77670 #77670
User since
2003-08-04
12209 Artikel
Admin1
[Homepage]
user image
ein schneller hack:
Code: (dl )
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, []);

aber Data::Dumper hat auch ein paar optionen, und es gibt
sicher auch ein paar weitere cpan-module.\n\n

<!--EDIT|pq|1182288747-->
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. -- Damian Conway in "Perl Best Practices"
lesen: Wiki:Wie frage ich & perlintro Wiki:brian's Leitfaden für jedes Perl-Problem

View full thread Data::Dumper, nur etwas anders