From the Perl help:
-n assume "while (<>) { ... }" loop around program
This is purely a textual operation, so it gives this program:
while (<>) { $_{$F[0]}+=$F[1]}print"$_ $_{$_}"for keys%_;{ }
This is an abuse of the -n
switch because the while loop is closed early due to the unmatched }
in the original program. But the closing }
that is added by the -n
switch still needs to match with something, and that's why there needs to be an extra {
at the end of the program, even though it doesn't do anything.
In other words, the only reason the last {
is there is to not give a syntax error.