Error/Warning - what's "prettier" way of achieving purpose

Scott Penrose scottp at dd.com.au
Sun Nov 24 17:21:57 CST 2002


On Monday, Nov 25, 2002, at 07:34 Australia/Melbourne, Rick Measham 
wrote:

> At 6:34 AM +1100 25/11/02, David Dick wrote:
>> print $cgi->header if (not defined $DEBUG); # slightly different, it 
>> won't print the empty string ;)
>
> The whole point of 'unless' is to remove the 'if not' syntax so even 
> better would be:
> print $cgi->header unless defined($DEBUG);

I would tend to agree. The ternary operator (silly name isn't it :-) 
has some great uses. Especially so is if you want to provide a number 
of alternative inputs to a sub without wanting to use a temporary 
variable.

Therefore it would be 'reasonable' to do something like this.

	print "You are currently in " . (defined $DEBUG ? 'DEBUG' : 
'PRODUCTION') . " mode";

But in the example given where we need to do nothing if not debug, then 
Ricks example is probably the best.

Scott
-- 
Scott Penrose
Welcome to the Digital Dimension
http://www.dd.com.au/
scottp at dd.com.au

Dismaimer: Contents of this mail and signature are bound to change 
randomly. Whilst every attempt has been made to control said 
randomness, the author wishes to remain blameless for the number of 
eggs that damn chicken laid. Oh and I don't want to hear about 
butterflies either.




More information about the Melbourne-pm mailing list