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

Oh, it looks like some mistake I've done, and I can't understand what's wrong (look at the Re: Date Handling in Perl - it's similar).

I tried to use Conditional Operator to put the time (in seconds) to subtract in the $_ variable. It can be done the other way: my $subt = 0; $hour > 10 || $subt = 60*60*24; (in this case, you'll need to use $subt instead of $_)

Sorry if my advice was wrong.

Replies are listed 'Best First'.
Re^4: Date Handling in Perl
by Anonymous Monk on Jul 11, 2012 at 16:24 UTC

    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
      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.