use Data::Dumper; my $arrref = [[1,1],2,[1,1]]; my $w = 0; my $sum = 0; my $text = Dumper($arrref); while ($text =~ /(\[)|(\])|(\d+)/g) { $w++ if $1; $w-- if $2; $sum += $w * $3 if $3; } print $sum, "\n"; # "10"
In reply to Re: Iterating elements at different level
by betterworld
in thread Iterating elements at different level
by punitpawar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |