#!/usr/bin/perl # uniq.pl: remove repeated lines. use English; use diagnostics; $oldline = ""; $n = 0; while ($line = <>) { unless ($line eq $oldline) { $n = $n + 1; print " $n $line"; } $oldline = $line; }
I know that this is not right, it prints out just a straight increment of the output lines. I think that I need to combine the process so that the count stops at the end of each set of lines which I can do, but I can't work out how to print only the single line along with the number?
Edit by BazB - add code tags.
In reply to Re^2: counting lines in perl
by imhotep
in thread counting lines in perl
by imhotep
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |