Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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.


In reply to Re: Juniper Router Audit by danger
in thread Juniper Router Audit by cleen

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Domain Nodelet?
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this?Last hourOther CB clients
    Other Users?
    Others perusing the Monastery: (4)
    As of 2025-01-20 16:32 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Which URL do you most often use to access this site?












      Results (59 votes). Check out past polls.