Re: Need help with a Perl Script Error
From: Joe Smith (Joe.Smith_at_inwap.com)
Date: Sun, 04 Apr 2004 09:36:29 GMT
Darren Clark wrote:
> #Strip directory structure
> $name=~m/^.*(\\|\/)(.*)/; # strip the remote path and keep the filename
> my $newname = $2;
You are blindly using $2 without bothering to check if m// succeeded. That
is guarenteed to fail for $name="My G5:Main directory:Subdir:File Name".
At bare minimum, change that to
my $newname = $name =~ s/.*[/:\\]//;
or "use File::Spec;" to split off the directory part.