Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Juerd had some reasonable points against the use of CGI. He said:
The short version:
It is slow (huge), has awful parsing (I just don't like it), a very annoying hybrid interface and too much junk code that is there for (backwards) compatibility. And it doesn't use strict, and has many globals.

Well I personally strongly support CGI, avoiding parameter cleansing and all the rest sounds great to me. However Juerd mentions some very good reasons against, which I can't refute. So, since you don't need all the things that CGI provides perhaps you should consider CGI::Simple which is faster, uses strict and is a very clean and nice reimplementation of CGI, by our very own tachyon :).

As everyone else says, I also recommend using more modules. Particularly something like Mail::Sendmail.

Things like this:

$$redirect = $$formdata{'redirect'} unless ($$formdata{'required'} eq +"");
can be better (more clearly) written as:
$$redirect = $formdata->{redirect} if ($formdata->{required} ne "");
And if it's appropriate, you might write it like this instead:
# sets unless $formdata->{redirect} is # a) undefined b) "" or c) 0 $$redirect = $formdata->{redirect} if $formdata->{required}; # this sets it only if $formdata->{redirect} is defined # ($formdata->{redirect} may be "" or 0 if already # initialized to that value) $$redirect = $formdata->{redirect} if defined($formdata->{required};
Either way, notice that the -> notation makes it much easier to see that $formdata is a reference to a hash of scalars. I've changed your unless eq to an if ne because in my experiences it's easier for someone to read. Trailing unlesses are great if the condition is simple such as next unless $name; but they start cluttering things if the reader has to evaluate the condition in their head and then take the complement of that.

Another style note, is that your indentation really ought to be consistant, although I hope that the inconsistancies I see here are due to cut-n-paste effects, for example "sent_email" is very difficult to read.

Hope it helps.


Update: Juerd is of course correct, the two lines are technically equivalent. I'd choose the version I've suggested because I expect that none of my students would understand the first straight off. Of course few of the students would understand the second straight off either... but it'd be easier for me to explain. ;)

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

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, 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, 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?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (5)
    As of 2018-05-20 20:10 GMT
    Find Nodes?
      Voting Booth?