Your code looks roughly correct for the behavior you are expecting.
Some minor changes:
- The second chomp call should be removed.
- added Data::Dumper to inspect to dump output
- attached $key lexical to a smaller scope
- add error checking to file open
- close filehandle when done reading it
- lexical filehandle $IN1 rather than global filehandle IN1
#!/usr/bin/perl
use strict;
use warnings;
use open IN => ':utf8';
use open OUT => ':utf8';
use Encode;
use Data::Dumper;
my $file1 = shift;
my %hash;
open( my $IN1, "<:encoding(utf8)", $file1 ) or die;
while (<$IN1>)
{
chomp;
my ($video, $p) = split /\t/;
push( @{$hash{$video}}, $p );
#print "array of hash of $video <==== $p\n";
}
close $IN1;
foreach my $key ( keys %hash )
{
print "$key: @{ $hash{$key} }\n"
}
print Dumper \%hash;
output:
mv89psg6zh4: A bird in a sink keeps getting under the running water fr
+om a fauc
et. A bird is bathing in a sink. A bird is splashing around under a ru
+nning fau
cet. A bird is bathing in a sink. A bird is standing in a sink drinkin
+g water t
hat is pouring out of the facet. A faucet is running while a bird stan
+ds in the sink below. A bird is playing in a sink with running water.
+ A bird is playing in tap water. A bird is bathing in the sink. A bir
+d is taking a bath.
$VAR1 = {
'mv89psg6zh4' => [
'A bird in a sink keeps getting under the r
+unning water from a faucet.',
'A bird is bathing in a sink.',
'A bird is splashing around under a running
+ faucet.',
'A bird is bathing in a sink.',
'A bird is standing in a sink drinking wate
+r that is pouring out of the facet.',
'A faucet is running while a bird stands in
+ the sink below.',
'A bird is playing in a sink with running w
+ater.',
'A bird is playing in tap water.',
'A bird is bathing in the sink.',
'A bird is taking a bath.'
]
};