Search code examples
perl

perl print current year in 4 digit format


how do i get the current year in 4 digit this is what i have tried

 #!/usr/local/bin/perl

 @months = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
 @days = qw(Sun Mon Tue Wed Thu Fri Sat Sun);
 $year = $year+1900;
 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
 print "DBR_ $year\\$months[$mon]\\Failures_input\\Failures$mday$months[$mon].csv \n";

This prints DBR_ 114\Apr\Failures_input\Failures27Apr.csv

How do I get 2014?

I am using version 5.8.8 build 820.


Solution

  • Move the line:

    $year = $year+1900;
    

    To after that call to localtime() and to become:

    ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
    $year = $year+1900;