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 ( [id://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?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2025-12-14 13:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (94 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.