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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|