in reply to Re: Re: "Correct" program style questions
in thread "Correct" program style questions
Of course, I can't say that mine is much clearer in that regard.
It isn't. I felt ickier the more I looked at that code for handling params too.
There is no reason to try to differentiate between undef and the empty string in this case. Interpolated, printed, or otherwise stringified, undef is an empty string. So,
is equivalent to# Cargo-cultish version with a temp variable. my $_name = param('name') || ''; my ($name) = $_name =~ /^([[:alpha:]]+)$/;
which is also equivalent to# BrowserUk's cargo-cultish only version. my ($name) = (param('name') || '') =~ /^([[:alpha:]]+)$/;
# My preferred version. my ($name) = param('name') =~ /^([[:alpha:]]+)$/;
Using the construct param('name') || '' at all is questionable. It throws away information. CGI returns an empty string in the case that the parameter was submitted with no value and undef in the case that it wasn't submitted at all. If you need to differentiate between those cases then you can check for undef. If you don't need to, you can ignore the difference (as above.)
-sauoq "My two cents aren't worth a dime.";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Re: Re: "Correct" program style questions
by BrowserUk (Patriarch) on Oct 23, 2002 at 22:33 UTC | |
by sauoq (Abbot) on Oct 24, 2002 at 01:09 UTC | |
by BrowserUk (Patriarch) on Oct 24, 2002 at 01:21 UTC | |
by sauoq (Abbot) on Oct 24, 2002 at 01:53 UTC | |
by BrowserUk (Patriarch) on Oct 24, 2002 at 02:58 UTC | |
| |
by Ovid (Cardinal) on Oct 24, 2002 at 14:27 UTC |
In Section
Seekers of Perl Wisdom