Like ichimunki, I won't really say much beyond style, and
in particular, deep nested conditionals.
As one example of reducing the complexity of your nesting (but
different than ichimunki's suggestion of using logical operators),
here is an alternate version of the foreach loop found within the
getintnames() routine -- your loop was 26 lines long and 4 levels
deep (with a couple of unnecessary indentations added as well).
foreach my $fpc (@lines) {
if ($fpc =~ /Slot (\d+?).*$/) {
$slotcounter = 1;
$slot = $1;
next;
}
next unless $slotcounter eq 1;
next unless ($cardtype, $pic) = $fpc =~ /PIC (\d+?)\s+(.*?)\,.*$/;
next unless $cardtype =~ /$type/;
($ports = $cardtype) =~ s/^(\d)x.*/$1/;
push @cardz, "so-$slot/$pic/$_" for 0 .. $ports - 1;
}
Note, I removed your $knownthing variable altogether as you
didn't really do anything with it. Also note, I can't really test
the above for errors beyond syntax, so for that reason just consider
it model rather than a plug-in alternative.
And a final note: my point was not to reduce the size of the
loop, that was only a side-effect of reducing the nesting. However,
some people frown at multiple points of escaping a loop iteration
(though in this case the nested ifs amount to the same thing), so
tmtowtdi and ymmv.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|