I’m trying to run this Perl script but it is not running as required. It is supposed to store the values of folders name which are in the format of date( example : 11-03-23)
I have some folders placed at this location in my account:
/hqfs/datastore/files
11-02-23 11-02-17 11-04-21
I’m storing these in “processed_dirs.dat” file.
But in the output: I got "pst12345678" in processed_dirs.dat
And when I printed $dh, I got GLOB(0x12345) some thing like this:
Please help me in getting the right output.
#!/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 = '/hqfs/datastore/files'; # 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-07-25'} readdir $dh;
closedir $dh or die "Unable to close $dir $!";
my %processed = map {$_ => 1} @dir;
store \%processed, 'processed_dirs.dat';
You are missing an argument for -d. Try
-d "$dir/$_" && .... (Unless the current directory is always going to be the directory you are reading.)There is almost no reason to ever use store instead of Storable::nstore.
Why were you trying to print dh?