in reply to Frequency occurence of same words in a file

You need to split each input line or otherwise extract the 2 items from it. Here is an SSCCE:

#!/usr/bin/env perl use strict; use warnings; my %count; while (my $line = <DATA>) { my ($key, $field) = split / +/, $line; push @{$count{$key}}, $field; } for my $key (sort keys %count) { print "$key ---> " . scalar @{$count{$key}} . "\n"; print $_ for @{$count{$key}}; print "\n"; } __DATA__ 0011 Sally 1122 Brandon 2233 George 0011 Roy 1122 Simson

🦛

Replies are listed 'Best First'.
Re^2: Frequency occurence of same words in a file
by geek12 (Novice) on Mar 24, 2022 at 22:52 UTC
    Hi, This is not giving the output as I want. Output I want is like below:
    0011 ------> 2 Sally Roy 1122 ------> 2 Brandon Simson 2233 -------->2 George
      Sorry, I tried printing just the below:
      print "@{$count{$key}}\n";
      and it gives what I am looking for. thank you for your help.