in reply to Directory creation with current Date

use POSIX qw(strftime); $parent_dir = "c:\\backups"; $formatted_date = strftime("%d-%B-%Y", localtime); mkdir("$parent_dir/$formatted_date") or die("...: $!");

You might want to go with a format that's string-sortable, like YYYY-MM-DD:

$formatted_date = strftime("%Y-%m-%d", localtime); # YYYY-MM-DD $formatted_date = strftime("%F", localtime); # Same as prev line

Replies are listed 'Best First'.
Re^2: Directory creation with current Date
by ZlR (Chaplain) on Jan 19, 2005 at 08:21 UTC
    Hello,

    Usually I want to avoid the load of the POSIX module so here is what i do :

    $formatted_date = now_date() ; sub now_date { my @now = localtime ; my $now_day = $now[3] ; my $now_year = $now[5] + 1900 ; my $now_month = $now[4] + 1 ; if ($now_month < 10) { $now_month = "0".$now_month } if ($now_day < 10) { $now_day = "0".$now_day } my $now_scal = join "-", ( $now_year, $now_month, $now_day ) ; return $now_scal ; }
    Update: I guess it's better with sprintf, like mkirank does :
    sub now_date { my @now = localtime ; my $now_day = $now[3] ; my $now_year = $now[5] + 1900 ; my $now_month = $now[4] + 1 ; $now_scal = sprintf "%04d-%02d-%2d", $now_year , $now_month ,$now_ +day ; return $now_scal }
    More Update: As demerphq says it could in the end very well be much better to use POSIX qw(strftime)
    Coding practice evolve !

      Usually I want to avoid the load of the POSIX module so here is what i do

      Why do you want to avoid POSIX?

      ---
      demerphq

        Why do you want to avoid POSIX?

        I know it's in the standard distribution and I'm sure loading it will not be significant at all but ... if it's not *really* needed, well, it's just one less module to load :)

Re^2: Directory creation with current Date
by PhilHibbs (Hermit) on Jan 20, 2005 at 13:54 UTC
    You can do $parent_dir = "c:/backups/"; in Windows which I find easier.