Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://750295]
help
Chatterbox?
[choroba]: :-)

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2018-02-21 14:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When it is dark outside I am happiest to see ...














    Results (281 votes). Check out past polls.

    Notices?