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

  • SEARCH
  • Home
  • 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 6188981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:19:48+00:00 2026-05-24T02:19:48+00:00

In the below perl script, I check my folder name (which is in the

  • 0

In the below perl script, I check my folder name (which is in the date format like 11-08-31) with the current date. If it matches, I process the folder. It also checks the previous day folder if there is no folder in today’s date. I already asked this type of question here but I need to make some changes here and add new features as well:

  • The script checks for the previous date if todays not find. But I need to check if the previous date has already been processed or not so that I donot process it again. So, Do I need to create a list for it?

  • This script checks only for the one previous date. What if I have to check for the 2 previous days? Thanks for your help. hope you understand my doubts.

Updated: 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


#!/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. $!";
}
  • 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-24T02:19:49+00:00Added an answer on May 24, 2026 at 2:19 am

    Well, another way to do it, as suggested by mugen kenichi, is to use Storable. This way stores a hash with all processed directories in it. Then when you run your program, it can check the hash to see if they have been processed.

    You would need a one-time script to set up the hash of processed directories.

    #!/usr/bin/perl
    use strict;
    use warnings;
    use Storable;
    
    # This script to be run 1 time only. Sets up 'processed' directories hash.
    # After this script is run, ready to run the daily script.
    
    my $dir = '.'; # or what ever directory the date-directories are stored in
    
    opendir my $dh, $dir or die "Opening failed for directory $dir $!";
    my @dir = grep {-d && /^\d\d-\d\d-\d\d$/ && $_ le '11-04-21'} readdir $dh;
    closedir $dh or die "Unable to close $dir $!";
    
    my %processed = map {$_ => 1} @dir;
    
    store \%processed, 'processed_dirs.dat';
    

    Then, a script to be run periodically to find and process your date directories.

    #!/usr/bin/perl
    use strict;
    use warnings;
    use File::Copy;
    use Storable;
    
    my $dir = shift or die "Provide path on command line. $!";
    
    my $processed = retrieve('processed_dirs.dat'); # $processed is a hashref
    
    opendir my $dh, $dir or die "Opening failed for directory $dir $!";
    my @dir = grep {-d && /^\d\d-\d\d-\d\d$/ && !$processed->{$_} } readdir $dh;
    closedir $dh or die "Unable to close $dir $!";
    @dir or die "Found no unprocessed date directories";
    
    my $fdir = '/some/example/path';
    
    for my $date (@dir) {
        my $dday = "$dir/$date";
        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 $zf to $fdir. $!";
        }
        $processed->{ $date } = 1;
    }
    
    store $processed, 'processed_dirs.dat';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Perl script which nests foreach loops as seen below. It takes
I've an annoying ASP.NET problem: I have a Perl script (see below), which gets
I have a perl script which is used to process some data files from
I have a Perl script, the relevant bits of which are posted below. #
I've written the Perl script below which generates a warning and I can't work
Is there a difference between the two examples below for beginning a Perl script?
I am doing the below in a perl script: my @pm1_CS_missing_months = `sqlplus -s
I wrote the following Perl script (below) in order to create simple XML file.
I have an SQL file which will give me an output like below: 10|1
My Perl Script retrieves the argument in the below way. Have Getoptions function to

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.