geek12 has asked for the wisdom of the Perl Monks concerning the following question:
Input file: 0011 Sally 1122 Brandon 2233 George 0011 Roy 1122 Simson
I want the output as mentioned above where words occurring on the left column is counted on the frequency of words listed and also printing respective right hand words mapping to left hand side coulmn words. I have the following code:Output: 0011 ---> 2 Sally Roy 1122 ---> 2 Brandon Simson 2233 ---> 1 George.
But, the above code is not working with the right hand side coulmn inclusion. Can you please help me with it? Thank you.my %count; my $file = "Input file"; open my $fh, '<', $file or die "Could not open '$file' $!"; while (my $line = <$fh>) { foreach my $str ($line) { $count{$str}++; } } foreach my $str (sort keys %count) { printf "%-31s %s\n", $str, $count{$str}; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Frequency occurence of same words in a file
by hippo (Archbishop) on Mar 24, 2022 at 22:32 UTC | |
by geek12 (Novice) on Mar 24, 2022 at 22:52 UTC | |
by geek12 (Novice) on Mar 24, 2022 at 22:56 UTC | |
|
Re: Frequency occurence of same words in a file
by davido (Cardinal) on Mar 25, 2022 at 06:15 UTC | |
by geek12 (Novice) on Mar 25, 2022 at 17:13 UTC | |
|
Re: Frequency occurence of same words in a file -- oneliner
by Discipulus (Canon) on Mar 25, 2022 at 08:28 UTC | |
by geek12 (Novice) on Mar 25, 2022 at 17:15 UTC | |
|
Re: Frequency occurence of same words in a file
by LanX (Saint) on Mar 24, 2022 at 22:12 UTC | |
by geek12 (Novice) on Mar 24, 2022 at 22:15 UTC |