in reply to Reading a spreadsheet

No need to read in reverse, just move the contents of the else block to immediately after the foreach loop. The loop will end when the data is exhausted, and the if clause inside will ensure that only valid data is sent.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: Reading a spreadsheet
by Anonymous Monk on Feb 18, 2015 at 16:37 UTC
    Do you mean by remove the "ELSE" block and move its content immediately after the second foreach loop?

      Yes, exactly.

      (My eye must have skipped — I failed to register that there are two nested foreach loops, or I would have been clearer in my answer. It’s no excuse, but still ... indentation matters!)

      Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

        This is what you are saying?
        ... foreach my $worksheet (@{$excel_sheet -> {Worksheet}}) { $worksheet -> {MaxRow} ||= $worksheet -> {MinRow}; # Skip worksheet if it doesn't contain data. next if $worksheet -> {MinRow} > $worksheet -> {MaxRow}; foreach my $row ($worksheet->{MinRow} .. $worksheet->{MaxRow}) { # Send flag as DONE once it reach the end of file or if there is + no data send_data( zipcode => 'DONE', # Flag ); # Correct values or skip them: next unless defined $worksheet->{Cells}[$row][0]->{Val}; warn Dumper $worksheet->{Cells}[$row][0]->{Val}; if ( $worksheet->{Cells}[$row][0]->{Val} =~ /^\d{5}/ ) { my $xlsx_rows = $worksheet->{Cells}[$row]; # Send data send_data( zipcode => $xlsx_rows->[0]->{Val} || '', firstname => $xlsx_rows->[1]->{Val} || '', lastname => $xlsx_rows->[2]->{Val} || '', ); } } } ...

        It still gets the data with the "DONE" on top.