in reply to Re^4: Converting Excel to Hash
in thread Converting Excel to Hash
See perlintro and perldsc maybe.
The idea is to initialize $data{ $master_key } with an empty array for each id and then to push every found element onto that array:
... $data{$master_key} ||= []; # if we haven't seen $master_key yet, creat +e a fresh array my %this_set; for my $col(1 .. $eSheet->{MaxCol}) { # Some logging for debugging if( !defined $eSheet->{Cells}[$row][$col]) { print "Row $row: skipping empty column $col\n"; next; }; my $key= $eSheet->{Cells}[0][$col]->Value; my $value = $eSheet->{Cells}[$row][$col]->Value; $this_set{$key}=$value; } } # Store our found set for that ID: push @{ $data{ $master_key }}, \%this_set;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Converting Excel to Hash
by ravi179 (Novice) on Jan 04, 2017 at 09:49 UTC | |
by poj (Abbot) on Jan 04, 2017 at 11:04 UTC | |
by ravi179 (Novice) on Jan 04, 2017 at 12:11 UTC | |
by ravi179 (Novice) on Jan 05, 2017 at 05:04 UTC |