nehavin has asked for the wisdom of the Perl Monks concerning the following question:
Hi Please look at the code below:
foreach my $i (0 .. $#tokens) { my $token = $tokens[$i]; $nested += $token->[1] if 'PAREN' eq $token->[0]; print $token->[1], $/ if 'FROM' eq uc $tokens[$i - 1][1] && 'TEXT' eq +$tokens[$i][0]; print $token->[1], $/ if 'JOIN' eq uc $tokens[$i - 1][1] && 'TEXT' eq +$tokens[$i][0]; print $token->[1], $/ if $nested = 0 && 'COMMA' eq $tokens[$i - 1][0]; + }
Here the "tokens" array is something like this: PAREN 1 PAREN 1 PAREN -1 and so on..... Now I need the variable "nested" to have cumulative sum of the 2nd column of the array. I get this result if I comment the print statements in the block, if i uncomment then the cumulative some doesn't work. I am a perl newbie and may be missing something trivial. Please help.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Cumulative sum not working as it should be
by BrowserUk (Patriarch) on Jan 07, 2014 at 10:02 UTC | |
by nehavin (Initiate) on Jan 07, 2014 at 10:30 UTC | |
by LanX (Saint) on Jan 07, 2014 at 10:40 UTC |