drecaise has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, I'm stuck with what is probably very easy to do but I can't find how: Here is the code (simplified to the basic problem):
#!/usr/bin/perl -w use strict; use warnings; use Date::Format; my @lt = localtime(); my $timestring = strftime('%c', @lt);
In the above example I'd like to get rid of the @lt variable and call localtime() directly from strftime(). Thing is that I don't know how to call it in a way that will return an array. I've been fiddling with it but couldn't figure out how this is done.

Replies are listed 'Best First'.
Re: How to use localtime() in another function ( in list context)
by GrandFather (Saint) on Feb 03, 2011 at 08:25 UTC

    You could use the following slightly skanky trick to appease the prototype that is provided for strftime:

    my $timestring = strftime('%c', @{[localtime()]});

    which creates a temporary array reference then dereferences it.

    True laziness is hard work
      Aah that's it :) Thank you very much!
Re: How to use localtime() in another function ( in list context)
by ikegami (Patriarch) on Feb 03, 2011 at 09:11 UTC

    Alternatively, you could bypass the prototype (by using "&") and pass it what it actually wants, a ref to an array.

    my $timestring = &strftime('%c', [ localtime() ]);
Re: How to use localtime() in another function ( in list context)
by jwkrahn (Abbot) on Feb 03, 2011 at 09:56 UTC

    Use POSIX::strftime instead?