Hi Poj your code has worked for me,thank you so much but actually in the output i am gettingvar$1={'apple-A'=>['30','40','50','60']} How to get rid of the single quotes for the values 30,40,50,60
input file data
name jan feb mar apr
apple 30 40 50 60
orange 25 54 45 45
Please find the code below
#!/usr/bin/perl
use strict;
use warnings;
use IO::All;
use Data::Dumper;
my @lines = io('test_Scores.txt')->chomp->slurp;
splice @lines, 0, 1; # remove first line
my %hash;
foreach my $line (@lines) {
$line =~ s/^\s+//;
my @elements = split /\s+/, $line;
my $key = join '-',splice @elements, 0, 2;
$hash{$key} = \@elements if length($key) > 0;
}
print Dumper \%hash;
|