in reply to Converting between localtime scalar and list contexts

Um, why not just call it in both contexts? Just get the current time using time(), then pass it to localtime:

my $time = time; my $ctime = localtime($time); my @timeArray = localtime($time);
Or, see the POSIX module's strftime() time formatting routine that would allow you to take @timeArray above and format it however you wish.

Replies are listed 'Best First'.
Re: Re: Converting between localtime scalar and list contexts
by cforde (Monk) on Jun 06, 2001 at 01:13 UTC
    A warning on doing this kind of thing. Notice that bikeNomad determined the time only once; the other time values are based on it. That's very important 'cause if you do it this way:
    my $time = time; my $ctime = localtime; my @timeArray = localtime;
    which might seem more "natural", you leave yourself open to a very subtle and obsure bug: What if the second changes between one of those calls? It might look like an "off-by-one" error, but it only happens "sometimes". Maybe nothing serious happens. But what if midnight occurs between one of those calls? Depending on what you're doing with @timeArray and $ctime you will get inconsistent results. This could hurt. I have seen it happen.

    Have fun,
    Carl Forde