Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
First off, this looks a lot like something from Mr. Wright. Bag it. Use Mime::Lite or something like that for the mailing. But kudos for using pass-by-ref. I see lots of pass-by-val, and that drives me nuts. A couple of other things, but maybe just preference:

  • If you're printing to STDOUT in various places, set $|=1; Otherwise, push everything onto an array, and just dump the whole array when you're done.
  • I don't use the C-style of bracketing. Too hard for me to read. Rather:
    sub function { # code in here }

    This keeps the brackets lined up vertically, and helps me keep track of deeply nested loops. Of course, this is certainly preference, and doesn't really have much to do wrt the code.

  • Dump the "&" in front of subroutine calls.
  • Likewise, dump the quotes in hashkeys, unless you got whitespace in there. Of course, if you have whitespace in your hashkeys, camelBack them or use _ or something. I'm all for saving keystrokes!
  • If you're using a hash, then use the hash:
    @$required = split /,/, $$formdata{'required'} unless ($$formdata{ +'required'} eq ""); $$redirect = $$formdata{'redirect'} unless ($$formdata{'required'} + eq ""); . . .

    I hate stuff like this. Assigning variables to hash values, IMHO, should only be done if you have some really complex data structures, and even then, I believe you should use some sort of interpolation, lest you continue to de-ref every time you access something.

  • Again, maybe just style: Unless it's a small hack, a never define vars outside of subroutines. You forget a my, and all hell could break loose. For more on what I'm getting at, look here
  • If/then is your friend:
    $method = "<font face=verdana size=1>An error with the script's in +stallation has occured. Please contact the webmaster with the error messages listed be +low!" if $method == 0; $method = "<font face=verdana size=1>An error occured with your su +bmission. Please check the errors and make any necessary modficiations!</font>" + if $method == 1;

    Use standard if-then/ternary syntax here. Make perl figure out which case you're on before assigning the $method values. AFAIK, in your code, it assigns the value, then will pitch it if the conditional isn't met. Don't waste the cycles.

  • HTH, and again, much of this may be just preference.
    ÅßÅ×ÅßÅ
    "It is a very mixed blessing to be brought back from the dead." -- Kurt Vonnegut


    In reply to Re: Some suggestions on coding style - a chance to critique by abaxaba
    in thread Some suggestions on coding style - a chance to critique by emilford

    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 imbibing at the Monastery: (6)
    As of 2024-03-28 14:13 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found