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

I am getting an error using POSIX . strftime. I followed the guidelines mentioned in perldoc http://perldoc.perl.org/functions/localtime.html

what is the mistake I did here

use strict; use warnings; use POSIX qw(strftime); my $datestring = strftime "%B %d %Y", localtime; print("date - $datestring\n");

Output message :
Usage: POSIX::strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = - 1, isdst = -1) at C:\Users\asdsa\Desktop\testmail.pl line 4.

Replies are listed 'Best First'.
Re: Error while using POSIX strftime
by Corion (Patriarch) on Sep 16, 2014 at 20:44 UTC

    I cannot reproduce that error.

    Code used:

    use strict; use warnings; use POSIX qw(strftime); my $datestring = strftime "%B %d %Y", localtime; print("date - $datestring\n");

    Output

    date - September 16 2014

    Perl version

    This is perl 5, version 16, subversion 3 (v5.16.3) built for MSWin32-x +64-multi-t hread Copyright 1987-2012, Larry Wall Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 5 source ki +t. Complete documentation for Perl, including FAQ lists, should be found +on this system using "man perl" or "perldoc perl". If you have access to + the Internet, point your browser at http://www.perl.org/, the Perl Home Pa +ge.
Re: Error while using POSIX strftime
by Anonymous Monk on Sep 16, 2014 at 20:08 UTC

    This code doesn't compile, and when I add the missing my, the code works for me. Please post code that compiles and reproduces the problem.

    Note that you probably want to use print instead of printf.

      Yes. It throws the same error after adding "my" as well. Updated the code. But I am still getting the same error.

        Item 2 and 4 on the Basic debugging checklist: look at your data.

        use strict; use warnings; use POSIX qw(strftime); my @lt = localtime; use Data::Dumper; print Dumper(\@lt); my $datestring = strftime "%B %d %Y", @lt; print("date - $datestring\n");

        Please post the output.

        What version of Perl are you using? Perhaps it is a bug in an old version of POSIX
        perl -v