Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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

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

  • 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.
Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2024-04-19 21:33 GMT
Find Nodes?
    Voting Booth?

    No recent polls found