Count & display occurrences of unique lines from STDIN. ie:
$ getocc.pl somefile
1: this line
2: these lines
$
#!/usr/bin/perl while(<>) { chomp $_; map {$hash{$_}++ => $_} $_; } map {print ("$hash{$_}: $_\n") => $_ } sort keys %hash;

Replies are listed 'Best First'.
Re: Occurrences of line.
by MidLifeXis (Monsignor) on Apr 12, 2005 at 17:05 UTC
    Why the map inside of the while?

    --MidLifeXis

Re: Occurrences of line.
by grinder (Bishop) on Apr 13, 2005 at 13:37 UTC

    Why the map outside the while?

    print "$hash{$_}: $_\n" for sort keys %hash;

    - another intruder with the mooring in the heart of the Perl