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

comment on

( [id://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.

jarich

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

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 contemplating the Monastery: (5)
As of 2024-03-28 08:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found