Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6136655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:37:46+00:00 2026-05-23T17:37:46+00:00

I am running a perl script. In my perl script, I check the current

  • 0

I am running a perl script. In my perl script, I check the current date and the folder name(which is also in the date format like for example 11-12-07). This perl script run automatically when It checks the curent date with the folder name. The folder is a tar folder which is loaded from other server.

So, basically I need to run the script if it matched with the folder name and current date.

Problem: Sometimes, I used to get the folder next day and my perl script checks only for the current date. The folder i get has the name which is previous date (not the current date).So, I need to do processing of the folder manually. I need to automate it in my perl script.

Please suggest me some ideas to make it happen.

Thanks!!

Code for Reference:

my $tfilename = 'tarmd5.tar';
my $td = `date '+%y-%m-%d'`;    # date in yy-mm-dd format
chomp ($td);
my $td2 = `date '+%Y%m%d'`;     # date in yyyymmdd format
chomp ($td2);


#
# get directory from command line
$dir = shift;
leave("'$dir' is not a valid directory") unless (-d $dir);
if    ($dir eq '.') {$dir = cwd();}
elsif ($dir !~ /^\//) {$dir = cwd()."/$dir";}


# print out the time
print scalar(localtime()),"\n";


######## This section unpacks transferred data ########
# go to directory for today and find *tar.gz files to copy

my $dday = "$dir/$td";
next unless (-d "$dday");
@gzfiles = glob("$dday/*tar.gz");
foreach $zf(@gzfiles) {
  next if (($zf =~ /BMP/) || ($zf =~ /LG/) || ($zf =~ /MAP/) || ($zf =~ /STR/));
  print "$zf\n";
  ($status,$message) = systemcall("/bin/cp $zf $fdir");
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:37:46+00:00Added an answer on May 23, 2026 at 5:37 pm

    Maybe using DateTime to do the math. I redid the solution as the first was poorly written. Changed DateTime->today to DateTime->now because one wants the hms portion when converting back to the desired time zone (from ‘floating’ or ‘UTC’).
    Also used Perl functions instead of shelling out to the Unix system, (date functions, current working directory – cwd, and copy function).

    Update: elsif ($dir != /^\//) is incorrect. Changed to elsif ($dir !~ /^\//).

    #!/usr/bin/perl
    use strict;
    use warnings;
    use Cwd;
    use DateTime;
    use File::Copy;
    
    # set to your desired time zone
    my $today = DateTime->now( time_zone => "America/New_York" );
    my $td = $today->strftime("%y-%m-%d");
    
    # strongly recommended to do date math in the 'floating'/UTC zone
    my $yesterday = $today->set_time_zone('floating')->subtract( days => 1);
    my $yd = $yesterday->set_time_zone('America/New_York')->strftime("%y-%m-%d");
    
    my $dir = shift or die "Provide path on command line. $!";
    
    if ($dir eq '.') {
        $dir = cwd;
    }
    elsif ($dir !~ /^\//) {
        $dir = cwd() . "/$dir"; 
    }
    
    opendir my $dh, $dir or die $!;
    my @dir = sort grep {-d and /$td/ || /$yd/} readdir $dh;
    closedir $dh or die $!;
    @dir or die "Found no date directories. $!";
    
    my $dday = "$dir/$dir[-1]"; # is today unless today not found, then yesterday
    my $fdir = '/some/example/path/';    
    my @gzfiles = glob("$dday/*tar.gz");
    
    foreach my $zf (@gzfiles) {  
        next if (($zf =~ /BMP/) || ($zf =~ /LG/) || ($zf =~ /MAP/) || ($zf =~ /STR/)); 
        print "$zf\n";
        copy($zf, $fdir) or die "Unable to copy. $!";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This seems redundant, running perl from a Perl script itself. my $Pref = &*())(*&^%$#@!;
I've got a Perl script I'm using for running a file processing tool which
Is it possible to have a Perl script run shell aliases? I am running
I have a perl script running on a Debian virtual machine on VMWare. This
Need a way to have a perl script running on one machine run a
I am running Perl script under cygwin which takes input from <STDIN> and process
I'm writing a Bash script in which I am running a perl script which
I'd like to limit the memory usage for my Perl script, running on a
I'm a complete perl novice, am running a perl script using perl 5.10 and
I've had some trouble forking of processes from a Perl CGI script when running

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.