
toolic
User
Sep 6, 2009, 12:25 PM
Post #3 of 5
(2597 views)
|
Re: [toolic] Multi dimentional array problem
[In reply to]
|
Can't Post
|
|
... and here's a recursion example:
use warnings; use strict; my $ref = ['a',['b','c'],'d',['e',['y','z'],'f']]; my $depth = 0; process($ref); sub process { my $aref = shift; for my $x (@{$aref}) { if (ref($x) eq 'ARRAY') { $depth++; process($x); $depth--; } else { print "$depth $x\n"; } } } __END__ Prints out: 0 a 1 b 1 c 0 d 1 e 2 y 2 z 1 f If you just need to print out your data structure, you could use the core module, Data::Dumper.
(This post was edited by toolic on Sep 10, 2009, 9:30 AM)
|