Skip Menu |

This queue is for tickets about the Time-Piece CPAN distribution.

Report information
The Basics
Id: 71772
Status: resolved
Priority: 0/
Queue: Time-Piece

People
Owner: Nobody in particular
Requestors: degatcpan [...] ntlworld.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 1.20
Fixed in: (no value)



Subject: Passing localtime as a parameter silently fails
The code below prints "later1later1later2", instead of "later1later1later2later2" (version 1.2, perl 5.10.1) use Time::Piece; my $lt = localtime; print "later1" if $lt > maketp(); #works print "later1" if localtime > maketp(); #works greaterthan($lt); #works greaterthan(localtime); # does not work sub greaterthan { my $lt = shift; print "later2" if $lt > maketp(); } sub maketp { Time::Piece->strptime("10 2 2011","%d %m %Y") }
This is not a bug, although it may be confusing. sub greaterthan { my $lt = shift } use Time::Piece; $x = localtime; # <-- first call greaterthan( $x ) greaterthan( localtime ); # <-- second call The difference here is that the first call to localtime is in scalar context. Time::Piece's localtime, in scalar context, returns an object. The second call is in list context. Time::Piece's localtime, in list context, returns the usual list. You can write this instead: greaterthan( scalar localtime ) -- rjbs