in reply to Re: counting lines in perl
in thread counting lines in perl
#!/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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: counting lines in perl
by Tanktalus (Canon) on Feb 26, 2005 at 20:41 UTC | |
by crashtest (Curate) on Feb 26, 2005 at 21:12 UTC | |
by imhotep (Novice) on Feb 26, 2005 at 22:24 UTC | |
by crashtest (Curate) on Feb 26, 2005 at 23:09 UTC | |
by imhotep (Novice) on Feb 26, 2005 at 23:57 UTC |