Weekly Perl Script
Steve Lane
sml at zfx.com
Mon Jun 21 13:12:44 CDT 1999
On the Jax.PM jacksonville-pm-list;
Steve Lane <sml at zfx.com> wrote -
Bill Jones wrote:
> The following is considered C-ish. Can you rewrite
> it to make it Perl-ish? Please do not worry
> about -w nor use strict solutions.
>
> if ($wday < $beginWeek || $wday > $endWeek) {
> $invalid = 1;
> } elsif ($hour < $axsStartHr) {
> $invalid = 1;
> } elsif ($hour >= $axsStopHr) {
> $invalid = 1;
> }
$invalid =
($wday < $begin_week || $wday > $end_week) ? 1
: ($hour < $axs_start_hr) ? 1
: ($hour >= $axs_stop_hr) ? 1
: 0;
you could of course combine the three conditions
into a single
$invalid = 1 if CONDITIONS;
statement, but i prefer the cascading ternary because
it keeps the different types of conditions separate.
it also gives you an easy default value (the : 0 at the end).
--
Steve Lane <sml at zfx.com>
The Jacksonville Perl Monger's Group is operated by -
Bill -Sneex- Jones ( sneex at usa.net ),
to whom send all praises, complaints, or comments...
More information about the Jacksonville-pm
mailing list