> 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?

In my experience, a lot of the fun of Perl is in the regular expressions.
So I would write

   #!/usr/bin/perl -w

   my @file_list;
   my $file_name;

   push @file_list,'01012003-Rattler.tar.gz';

   foreach $file_name (@file_list) {
      if ($file_name =~ s/^(\d{4})(\d{4})(.*)$/$2$1$3/) {
         print $file_name,"\n";
      } else {
         print "Error: unexpected file name: $file_name.\n";
      }
   }

Trying it at the command line, I get

   me:~> perl beginners.filenames.pl
   20030101-Rattler.tar.gz

Regards,

John Refior

Reply via email to