TGI has asked for the wisdom of the Perl Monks concerning the following question:
I am working on a l'il CGI script that needs to print times translated from epoch. When I wrote the bit that converts 24 hour time to 12hour time, I got some weird behavior.
The problem code would label everything as am. I'm not sure why.
This didn't work:
$hour > 11 ? $xm = "pm" : $xm = "am";
These did:
if ($hour > 11) {$xm = "pm"} else {$xm = "am"};
$hour > 11 ? ($xm = "pm") : ($xm = "am");
So how do I know when to use parentheses on ?: clauses? Is it better to always use them? I am quite confused.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Weird ?: behavior
by btrott (Parson) on Aug 08, 2000 at 22:57 UTC | |
by turnstep (Parson) on Aug 08, 2000 at 23:02 UTC | |
by tye (Sage) on Aug 08, 2000 at 23:18 UTC | |
|
Re: Weird ?: behavior
by tiny (Beadle) on Aug 08, 2000 at 23:59 UTC | |
|
Re: Weird ?: behavior
by KM (Priest) on Aug 08, 2000 at 23:03 UTC | |
|
Re: Weird ?: behavior
by Maclir (Curate) on Aug 09, 2000 at 02:10 UTC | |
|
Re: Weird ?: behavior
by TGI (Parson) on Aug 08, 2000 at 23:42 UTC |