Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Iterating elements at different level

by betterworld (Curate)
on Jan 12, 2016 at 17:53 UTC ( #1152586=note: print w/replies, xml ) Need Help??


in reply to Iterating elements at different level

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"

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1152586]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2022-12-03 10:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?