Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
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 perusing the Monastery: (5)
As of 2024-03-29 08:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found