Re: year not returned by Time::localtime



SteveP wrote:
Here is a snippet of code that illustrates my problem (or is it a bug?)

#!c:\perl\bin\perl
use Time::localtime; # overrides CORE::localtime
use Time::Local;
$nowYear = localtime->year();
$date = timelocal(0,0,0,1,3,$nowYear);
($sec,$min,$hr,$mday,$mon,$year,$wday,$yday,$isdst) =
CORE::localtime($date);
($sec,$min,$hr,$mday,$mon,$badyear,$wday,$yday,$isdst) =
localtime($date);

why did you think you could call Time::localtime::localtime like this?

From the documentation for Time::localtime:

This module's default exports override the core localtime()
function, replacing it with a version that returns ``Time::tm''
objects.

I think that if you check you'll find that all your variables except
$sec are undef (including $badyear) and $sec is actually a Time::tm
object....

$funYear = localtime($date)->year();
print "year [", $year, "] badyear [", $badyear, "] funYear = [",
$funYear, "]\n";

CORE localtime works as expected but the function oriented interface
doesn't return anything for year in an array return value. Shouldn't it
return the same thing as the explicit function?

why doyou think it has an "array return value" by which I suppose you
mean "list context"...

-jp

.



Relevant Pages

  • Help with a setfing value in structure
    ... and I can have a array of such structures, ... to set value of the core slot in the structure which is on ... ; undefined function: (SETF SSR-CORE) ... [Condition of type UNDEFINED-FUNCTION] ...
    (comp.lang.lisp)
  • Re: Distinguishing string and numerical context?
    ... >> vs. string context, it's array vs. scalar context. ... >> calls localtime() in array context, so it returns a list of numbers ...
    (comp.lang.perl.misc)
  • Re: 64 bits
    ... an array with>2 billion elements will not be unusual - same for ... With a 96 core CPU then 2 billion elements is just 20 million elements ... It doesn't matter if you can get a linear speedup from multicore, ... Even in the best case, with uniform memory access and perfect algorithms, you're looking at a linear speedup, not n log n. ...
    (comp.lang.java.programmer)
  • Re: FAQ 4.17 How do I find yesterdays date?
    ... The FAQ should say what it actually says (well, ... They are not part of the core. ... The core module Time::Local + localtime() are sufficient to answer the ... or - as I wrote - localtime and mktime (in POSIX). ...
    (comp.lang.perl.misc)
  • Re: calculating an array at runtime under C
    ... I realise I had some errors when explaining. ... you got me to the core of the problem. ... the array as an empty array and stuff it later. ...
    (alt.comp.lang.learn.c-cpp)