in reply to Re^3: Date Handling in Perl
in thread Date Handling in Perl

It's the ternary operator you've botched.

my $subst; for my $hour (5, 12) { $hour > 10 ? $subst = 0 : $subst = 86400; print $subst, "\n"; } for my $hour (5, 12) { $subst = $hour > 10 ? 0 : 86400; print $subst, "\n"; } ## output 86400 86400 86400 0

Replies are listed 'Best First'.
Re^5: Date Handling in Perl
by aitap (Curate) on Jul 11, 2012 at 17:11 UTC
    Thanks, it's smaller and was even stated in documentation:

    Because this operator produces an assignable result, using assignments without parentheses will get you in trouble. For example, this:

    $a % 2 ? $a += 10 : $a += 2

    Really means this:

    (($a % 2) ? ($a += 10) : $a) += 2

    I should have noticed it.

    Sorry if my advice was wrong.