Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Gee, it's actually not the worst Perl code I have seen by any stretch of the imagination. A couple of points:

  • the else is easier to see if it is not cuddled:
    rather than this: } else { use this: } else {
    which then gives the braces the same relative position fo the if and the else.
  • Carefully consider NOT using the unless it can be quite counter-intutitive when reading code.
  • Code is easier to read and flows more logically (IMHO) if you use block conditionals, for example:
    This: unless ( scalar(@downhosts) == 0 ) { print p, "There $verbage[2] ", scalar(@downhosts), " $verbage[3] +unreachable\n", br; } rather than: unless ( scalar(@downhosts) == 0 ) { print p, "There $verbage[2] ", sc +alar(@downhosts), " $verbage[3] unreachable\n", br }
    I see others have pointed out some different approaches to dealing with filehandles and the like. Only other suggestion I would make is to use CGI more effectively by not printing HTML directly - always use CGI/

    And finally, use perltidy. I have it in the toolbox in my Komodo so I can run it over my code any time. It actually mkes it easier to spot problems when I can see thngs like the indentation level go wrong! It also gives me a consistency of style I am too lazy to get any other way.

    jdtoronto


    In reply to Re: improving the aesthetics of perl code by jdtoronto
    in thread improving the aesthetics of perl code by tcf03

    Title:
    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?
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 chilling in the Monastery: (5)
As of 2024-04-24 18:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found