in reply to Counting within an array

use hash:
my %hash; while (<MYINPUTFILE>) { chomp; $hash{$_} ++; } $\ = "\n"; while (my ($k, $v) = each %map) { print $k, $v; }

Replies are listed 'Best First'.
Re^2: Counting within an array
by kennethk (Abbot) on Nov 30, 2010 at 14:04 UTC
    In order to meet the posted spec (output on every line), you can move the print statement into the while loop:

    my %hash; while (<MYINPUTFILE>) { chomp; $hash{$_} ++; print "$_$hash{$_}\n"; }
      That works like a charm, thank you very much.