Harinatha Reddy M wrote:
For example:
[ 9, [ 3, 4, [ [ 2 ] ] ] ] = 0
In 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: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/