I have a need to manipulate some filenames. The files are all in a
single directory. They are currently named in the form:
01012003-Rattler.tar.gz
01162003-Rattler.tar.gz
01312003-Rattler.tar.gz
02152003-Rattler.tar.gz
These are backup files from a machine. What I will ultimately be doing
is restoring them in date order. The problem is, the file date/time
cannot be trusted in all cases (some yes). I assume 'cp' was used at
some point along the way and 'changed' the file date/times. So all I
have is the filenames to put the files in date order. I believe this
would be the proper format to do this:
20030101-Rattler.tar.gz
20030116-Rattler.tar.gz
20030131-Rattler.tar.gz
20030215-Rattler.tar.gz
I wrote a short script to do this, and it will obviously work. My
question is, what are some of the other ways to do it?
Thanks,
Mike
#!/usr/bin/perl
use strict;
use warnings;
my $string = '03102003-Rattler.tar.gz';
my @bigarray = split ( '-', $string);
my $workstring = $bigarray[0];
my @sa = split ( //, $workstring);
my $newstring =
"$sa[4]$sa[5]$sa[6]$sa[7]$sa[0]$sa[1]$sa[2]$sa[3]-$bigarray[1]";
print "Old filename = $string\n";
print "New filename = $newstring\n";
--
IBM: Intriguingly Blue Motif
01:55:01 up 4 days, 9:53, 1 user, load average: 1.30, 1.28, 1.27
Linux Registered User #241685 http://counter.li.org
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/