in reply to Re^3: counting lines in perl
in thread counting lines in perl
Note: The program will hang if there isn't at least one line of data to read.#!/usr/bin/perl # uniq.pl: remove repeated lines. use strict; use diagnostics; my $oldline = <>; # Priming read my $n = 1; while (my $line = <>) { if ($line eq $oldline) { $n++; #$n = $n + 1; } else { print " $n $oldline"; $n = 1; $oldline = $line; } } if ($oldline) { print " $n $oldline"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: counting lines in perl
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 |