Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: "Correct" program style questions

by adrianh (Chancellor)
on Oct 23, 2002 at 21:39 UTC ( #207539=note: print w/ replies, xml ) Need Help??


in reply to "Correct" program style questions

The Once And Only Once bigot in me would force me to rewrite

my $_name = param('name') || ''; my $_color = param( 'color' ) || '';

as

my ($_name, $_color) = map {param($_) || ''} qw(name color);

My illogical fear that there would be at least one person in the world called '0' would then force me to rewrite the above as:

my ($_name, $_color) = map {defined($_) ? $_ : ''} map {param($_)} qw(name color);

As for the regex style... Personally I would go for traditional regexes if I was running a tutorial, since this is what most students would come across if they tried to follow up their perl work elsewhere. However that's just my preference - and depends on the audience and what they're expected to do with what their taught ;-)

I would also use the OO style of using CGI since I dislike namespace pollution - but that's just me.

I would also run encode_entities over $color as well as $name. I met a totally evil proxy a few years back that stripped HTML content to 7 bits and have been paranoid ever since!

AFAIK \p{IsAlpha} is exactly the same as using :alpha:.

(and are we ignoring uninitialised value warnings from the print if $name or $color don't match? :-)


Comment on Re: "Correct" program style questions
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://207539]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (11)
As of 2015-07-29 12:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (263 votes), past polls