in reply to Re^3: Adding text file data to hashes and array
in thread Adding text file data to hashes and array
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Adding text file data to hashes and array
by poj (Abbot) on Feb 15, 2019 at 07:58 UTC | |
by Anonymous Monk on Feb 15, 2019 at 12:05 UTC | |
by poj (Abbot) on Feb 15, 2019 at 13:01 UTC | |
|
Re^5: Adding text file data to hashes and array
by haukex (Archbishop) on Feb 15, 2019 at 08:35 UTC | |
by Tigor (Novice) on Feb 15, 2019 at 09:47 UTC | |
by haukex (Archbishop) on Feb 15, 2019 at 10:10 UTC | |
by Tigor (Novice) on Feb 15, 2019 at 11:10 UTC | |
by hippo (Archbishop) on Feb 15, 2019 at 11:58 UTC | |
|