Harinatha Reddy M wrote:
For example: [ 9, [ 3, 4, [ [ 2 ] ] ] ] = 0In this case we need to fnid the sum of 9, [3,4, [[2]]] So if we look at it in the equation format 9+ (-(3+4+ -(-(2)))) i.e 9+ (-(3+4+2)) = 9+ (-(9)) = 9-9 = 0
echo "[ 1, [ 2 ], [ 3 ] ]" | perl -ne' chomp; print; 1 while s/\[([^\]]*)\]/-($1)/; s/,/+/g; print " = ", -eval, $/; ' [ 1, [ 2 ], [ 3 ] ] = -4 -- Ruud -- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] http://learn.perl.org/
