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;
In reply to Re^4: Adding text file data to hashes and array
by Tigor
in thread Adding text file data to hashes and array
by Tigor
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |