in reply to Re: Wildcards for a wide array of strings?
in thread Wildcards for a wide array of strings?
Hello again zarath,
I noticed a few things on your code:
You do not need use File::Path; and use File::Glob;.
Also you do not need these lines, you do not do anything with the opendir(). You open and close the directory for no reason.
my $base = 'D:\\Some\\specific\\folder\\'; opendir (my $dhb, $base) or die "Cannot open ".$base.": ".$!; closedir $dhb;
I would prefer to get the time like this:
# 0 1 2 3 4 5 6 7 8 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(t +ime); # $mon the month in the range 0..11 , with 0 indicating January and 11 $mon += 1; # $year contains the number of years since 1900. To get a 4-digit year + write: $year += 1900;
By doing so, you do not need the package use Time::Piece;.
Update: I would also recommend to add and if() and else condition at your for loop. Also you can remove the else condition inside the loop in case the if() condition is not met it will jump straight to next;
if (@files) { foreach my $file (@files) { if ($file = glob(($base)."*.txt")){ move($file, $to) or die ("The move operation failed for ".$fil +e." because ".$!); print "Moved ".$file." to ".$to or die $!; } next; } } else { print "No files found to move\n"; }
These are some minor recommendations, hope you will love Perl and continue working on it.
|
|---|