in reply to Time::Piece, localtime -- ambiguous, parentheses
Eily beat me to it, but since I've already typed it up... ;-) B::Deparse to the rescue - the first two are localtime() - $x, while the third is localtime(-$x). The same is true if you're not using Time::Piece, which overrides localtime, but you also get a helpful warning. Interestingly, core localtime has a prototype, while Time::Piece::locatime doesn't.
$ perl -MTime::Piece -le 'print prototype("CORE::localtime"); print pr +ototype("Time::Piece::localtime")//"undef"' ;$ undef $ perl -MO=Deparse -e 'my $x = localtime; my $y = localtime - $x; prin +t "$y\n"; ' Warning: Use of "localtime" without parentheses is ambiguous at -e lin +e 1. my $x = localtime; my $y = localtime -$x; print "$y\n"; -e syntax OK $ perl -MO=Deparse -e 'use Time::Piece; my $x = localtime; my $y = loc +altime() - $x; print "$y\n"; ' use Time::Piece; my $x = main::localtime(); my $y = main::localtime() - $x; print "$y\n"; $ perl -MO=Deparse -e 'use Time::Piece; my $x = localtime; my $y = (lo +caltime) - $x; print "$y\n"; ' use Time::Piece; my $x = main::localtime(); my $y = main::localtime() - $x; print "$y\n"; $ perl -MO=Deparse -e 'use Time::Piece; my $x = localtime; my $y = loc +altime - $x; print "$y\n"; ' use Time::Piece; my $x = main::localtime(); my $y = main::localtime(-$x); print "$y\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Time::Piece, localtime -- ambiguous, parentheses
by ikegami (Patriarch) on Dec 06, 2018 at 03:43 UTC |