MLUG: Re: [UUG/MLUG] perl and y2k
Re: [UUG/MLUG] perl and y2k
Email address obfuscation in effect -- please click here to turn it off.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Jonathan King wrote:
> 
> On Wed, 5 Jan 2000, Stephen Montgomery-Smith wrote:
> 
> > > So is there a commonly known solution to make localtime spit out 00 or
> > > something that is a little more accurate than 100 (?)  I've seen
> > > this on several sites (including mine) =)
> >
> > How about:
> >
> > printf ('Submitted:  %02d/%02d/%02d  %02d:%02d:%02d', $month,
> >   $mday, $year%100, $hour, $min, $sec);
> >
> >           ^^^^^^
> 
> Yup, that's the right answer.
> 
> Along these lines, and while we all run off to fix our code, some of you
> might be interested in the fact that perl does something potentially
> unexpected with the % operator when the first argument is negative, so
> that:
> 
>     [EMAIL:PROTECTED]$ perl -e '$a=-98; printf("%02d\n",$a%100);'
>     02
> 

Hmmm, in my opinion (as a mathematician) that is the correct answer.
I would have expected -98 (in my opinion the wrong answer, but
what I think C does).

My recollection is that the book says that you cannot be sure what
answer you will get if the 1st argument is negative.

-- 

Stephen Montgomery-Smith              EMAIL:PROTECTED
307 Math Science Building             EMAIL:PROTECTED
Department of Mathematics             EMAIL:PROTECTED
University of Missouri-Columbia
Columbia, MO 65211
USA

Phone (573) 882 4540
Fax   (573) 882 1869

http://www.math.missouri.edu/~stephen