Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I need to get a count of how many unique data values I have in my text file.
The text file has data like this:
The text file has data like this:
I need the results of my script to look like this:123 56 123 56 234 45 123 56 678 93 678 93
Here is my attempt and its not printing any data:234 45 1 123 56 3 678 93 2
my $file = 'filehere.txt'; open(DATA, "$file") || die "Can not open: $!\n"; my @array = (<DATA>); close(DATA); open(DATA, "$file") || die "can t open: $!\n"; my %hash = (); foreach $item (@array) { $hash{$item}++; } print "$item\t$hash{$item}\n"; close(DATA);
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Hash and count of data values
by LTjake (Prior) on Aug 18, 2003 at 13:53 UTC | |
Re: Hash and count of data values
by monktim (Friar) on Aug 18, 2003 at 13:53 UTC | |
by Anonymous Monk on Aug 18, 2003 at 14:18 UTC | |
Re: Hash and count of data values
by bm (Hermit) on Aug 18, 2003 at 13:45 UTC | |
Re: Hash and count of data values
by gjb (Vicar) on Aug 18, 2003 at 13:51 UTC | |
Re: Hash and count of data values
by Cine (Friar) on Aug 18, 2003 at 13:53 UTC | |
by Fletch (Bishop) on Aug 18, 2003 at 13:56 UTC | |
Re: Hash and count of data values
by Anonymous Monk on Aug 18, 2003 at 13:54 UTC |
Back to
Seekers of Perl Wisdom