[Gllug] Poor scripting?!
Andrew Farnsworth
farnsaw at stonedoor.com
Tue Mar 11 15:09:39 UTC 2008
Henrik,
This won't work, mainly because the perl string operator 'eq' does not
recognize wild cards (i.e. the * character). You will need to do a
regex match to determine if ($_ =~ /cerprod$/) which will match the
string 'cerprod' at the end of the string contained within the $_ variable.
Andrew
Henrik Morsing wrote:
> 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