one hello
two world
three goodbye
two apple
one banana
####
one: hello, banana
two: world, apple
three: goodbye
####
push @{$hash_name{$key}}, $string;
####
$hash_name{$key}
####
push @{$hash_name{$key}}, $string;
####
one hello
two world
three goodbye
two apple
one banana
####
use strict;
use warnings;
use 5.010;
open my $INFILE, '<', 'data1.txt'
or die "Couldn't open file: $!";
my %hash;
while (<$INFILE>) {
chomp;
my ($first_col, $second_col) = split;
push @{$hash{$first_col}}, $second_col;
}
while ( my($first_col, $aref) = each %hash ) {
say "$first_col: ", join(', ', @$aref);
}
close $INFILE;
--output:--
three: goodbye
one: hello, banana
two: world, apple