http://www.perlmonks.org?node_id=750295


in reply to Re^2: Iterative Subroutine Approach Question
in thread Iterative Subroutine Approach Question

With regards to closing out your original foreach loop and starting a new one, that's exactly what I don't think you should do. It's possible, but it makes your code more complicated than it needs to be.

In the code you've given, you've got two separate foreach loops, each one having internal if-structures. Simply move all of the if-structures into a single large foreach loop, i.e.:
foreach my $row ($sheet->{MinRow}+18..$sheet->{MaxRow}){ if ($sheet->{Cells}[$row][2]->{Val} eq "SYSTEM") {$comment = $shee +t->{Cells}[$row-2][2]->{Val};} if ($sheet->{Cells}[$row][3]->{Val} eq "UPGRADE SOLUTION") {$upgra +de=1} else {$upgrade=0}; if ( $sheet->{Cells}[$rw][0]->{Val} =~ /(^\d+)/ ) { $line = $sheet->{Cells}[$rw][0]->{Val}; $qty = $sheet->{Cells}[$rw][1]->{Val}; ...
Doing that should make sure that $comment is set appropriately each time you get to a detail line, without the need for any more than the single, large foreach loop.

Replies are listed 'Best First'.
Re^4: Iterative Subroutine Approach Question
by finhagen (Sexton) on Mar 13, 2009 at 02:58 UTC
    Bellaire, You were right - your recommendation worked right out of the box. This is huge for me and my project. I am so grateful. Thank you!

    Hagen Finley

    Boulder, CO