You might find the task easier if you split it into 2 steps, first create an array with the missing data filled down and then create the hash. For example

#!perl use strict; use Spreadsheet::ParseExcel; use Data::Dumper; my $filename = "Book2.xls"; my $e = new Spreadsheet::ParseExcel; my $eBook = $e->Parse($filename); my $eSheet = $eBook->{Worksheet}[0]; my ( $row_min, $row_max ) = $eSheet->row_range(); my ( $col_min, $col_max ) = $eSheet->col_range(); # build array filling in blanks my @row_array =(); my @data_array=(); for my $row ($row_min .. $row_max ){ for my $col ($col_min .. $col_max){ my $cell = $eSheet->get_cell( $row, $col ); if ($cell && $cell->value ne ''){ $row_array[$col] = $cell->value; } } $data_array[$row] = [@row_array]; } print Dumper \@data_array; # convert array to hash my %data = (); for my $row ($row_min+1 .. $row_max){ my %set = (); my $master_key = $data_array[$row][$col_min]; for my $col ($col_min+1 .. $col_max){ my $key = $data_array[$row_min][$col]; $set{$key}= $data_array[$row][$col] } push @{ $data{$master_key} }, \%set; } print Dumper \%data;
update : push @data_array,[@row_array] changed
to $data_array[$row] = [@row_array] to allow for $row_min not being 0.
poj

In reply to Re^13: Converting Excel to Hash by poj
in thread Converting Excel to Hash by ravi179

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.