Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re^3: Iterative Subroutine Approach Question

by bellaire (Hermit)
on Mar 13, 2009 at 00:29 UTC ( #750295=note: print w/replies, xml ) Need Help??

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://750295]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2018-08-18 06:47 GMT
Find Nodes?
    Voting Booth?
    Asked to put a square peg in a round hole, I would:

    Results (185 votes). Check out past polls.