John W. Krahn writes:
> Jeff 'Japhy' Pinyan wrote:
[...]
> >   my $month = (split ' ', uc localtime)[1];
> >
> > localtime(), in scalar context, returns a string like
> >
> >   "Fri Oct 25 10:30:23 2002"
> >
> > I'm uppercasing it, splitting it on whitespace, and getting the 2nd
> > element ("OCT").
>
> And, of course, another way to do it:
>
> my $month = qw(JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV
> DEC)[(localtime)[4]];

This lost me for a moment. I figured it out by trying...

#!/usr/bin/perl
use warnings;
use strict;
# test "get uc month from localtime"

my $month = qw(JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV 
DEC)[(localtime)[4]];

print localtime,"\n";
my $x = localtime[4]; print "$x\n";
print "$month\n";

With this result:
325927910202990
Mon Apr 15 08:17:32 1974
OCT

I then made this change (added parens):
my $x = (localtime)[4]; print $x,"\n";  

which yields "9" as expected. (Your way might be better if I later want to 
change "OCT" to "October" or "10th month" etc.?)

So what did "localtime[4]" (without parens) do?

-Kevin

-- 
Kevin Pfeiffer
International University Bremen

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to