[Gllug] Poor scripting?!

Henrik Morsing henrik at morsing.cc
Tue Mar 11 14:41:16 UTC 2008


Hi, I've had a look and help from the #gllug folks (thanks!), does this look like it would do the same job, called as 'rename s/cerprod/$CRMDB/ s/medprod/$CRMDB /cerillion'?

#!/usr/local/bin/perl
#
# Usage: rename perlexpr perlexpr2 dir

use File::Find;

($regexp = shift @ARGV) || die "Usage:  rename perlexpr perlexpr2 directory\n";
($regexp2 = shift @ARGV) || die "Usage:  rename perlexpr perlexpr2 directory\n";
($dir = shift @ARGV) || die "Usage:  rename perlexpr perlexpr2 directory\n";

finddepth(sub { if ($_ eq "*cerprod") {
                   $old_name = $_;
                   eval $regexp;
                   die $@ if $@;
                   rename($old_name, $_) unless $old_name eq $_;
        } elseif ($_ eq "*medprod") {
                   $old_name = $_;
                   eval $regexp;
                   die $@ if $@;
                   rename($old_name, $_) unless $old_name eq $_;
        } },
        $dir);

}

exit(0);


Thanks in advance!

Henrik Morsing

-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list