in reply to Re: Reading a spreadsheet
in thread Reading a spreadsheet

Do you mean by remove the "ELSE" block and move its content immediately after the second foreach loop?

Replies are listed 'Best First'.
Re^3: Reading a spreadsheet
by Athanasius (Archbishop) on Feb 18, 2015 at 16:50 UTC

    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.

        No, “after the loop” means after the loop body, not after the loop condition:

        foreach my $worksheet (...) { ... foreach my $row (...) { ... if (...) # filter out unwanted data, including h +eader { send_data(...); # send data extracted from the spreadsh +eet } } } send_data(zipcode => 'DONE'); # NOW you're done!

        Hope that helps,

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