perl creating a new folder named with todays date

I have a perl script that opens a webpage, gets all the .txt links from the page and savesw each link as a file in $SaveDir

Right now $SaveDir is static  

my $SaveDir = "I:/SECDocs/20070730/";

Every time it runs, I manually have to create a new folder with a matching name.

I would like script to create a new folder everyday on its own like:
my $SaveDir = "I:/SECDocs/$TodaysDate/";

How do I set $TodaysDate to be todays date and create a folder with that name?

Heres what I have:

use strict;
use warnings;
use LWP::Simple;
use Data::Dumper;
use HTML::SimpleLinkExtor;

#Update these as necessary

my @Pages = (


my $SaveDir = "I:/SECDocs/20070730/";

      #Make sure SaveDir ends in /
      $SaveDir .= "/" unless $SaveDir =~ /\/$/;

foreach  my $Page (@Pages) {

      #Get page and it's links
      GetPageAndLinks($SaveDir, $Page);

sub GetPageAndLinks {
      my ($dir, $page) = @_;
      my $content = get($page);
      # Check the outcome of the response
      unless(defined($content)) {
            print STDERR "Could not get '$page': $@.\n";
      my $extor = HTML::SimpleLinkExtor->new();
      my @all_links = $extor->links;
      @all_links = grep {m!/Archives/edgar/data/.*\.txt!} @all_links;
      @all_links = map { $_ = "$_"; } @all_links;
      foreach my $one_link (@all_links) {
            my $FileName = $one_link;
            $FileName =~ s/.*[\/]//;   #Remove leading info
            $FileName =~ s/\?.*//;     #Remove trailing info
            getstore($one_link, "$dir$FileName");
      print "$FileName";

Who is Participating?
Adam314Connect With a Mentor Commented:
use POSIX qw(strftime);

my $TodaysDate= strftime("%Y%m%d",localtime);
mkdir($TodaysDate) or die "Could not create dir $TodaysDate: $!\n";
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.