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

Is there a way to do:
my ($day, $month, $year) = strftime "%d %m %Y", time();
Because that doesn't populate the array.

Replies are listed 'Best First'.
Re: create array from strftime
by ikegami (Patriarch) on Jun 20, 2012 at 17:45 UTC

    Problem #1: strftime doesn't take an epoch time for argument.

    Problem #2: strftime returns a single string.

    Then there's also the fact that "3 scalars" are not "an array".

    Solution:

    my ($day, $month, $year) = (localtime)[3,4,5]; $month += 1; $year += 1900;

    localtime.

      Or read the output of strftime(3). :)
      Here's another example:
      use POSIX qw(strftime); # POSIX is your friend # see man strftime(3) for format options my $gmtstring = strftime "%F %H:%I:%S %z", localtime; print $gmtstring;

      Hope this helps.


      my $perl_version( 5.12.4 );
      print $perl_version;
        How does one use that to populate $day, $month and $year?
Re: create array from strftime
by Anonymous Monk on Jun 20, 2012 at 17:44 UTC

    <serious joker>Sure, all you do is stuff some dynamite into your pants and light the fuze

    the opposite of strftime is strptime, DateTime comes with both