Link to home
Start Free TrialLog in
Avatar of skingsbu1
skingsbu1

asked on

Issue renaming a file

I am having an issue renaming a file with the File::Find module.

my @initial_directory = ("/Users/test/Development/sandbox/file_strip_example/files");

find (\&wanted, @initial_directory);

sub wanted {
return unless /\s$/;

my $new_name = $File::Find::name;
$new_name =~ s/ +$//; # Remove trailing spaces in the filename
chomp $new_name;

print "Renaming >>$File::Find::name<< to >>$new_name<<\n";
rename $File::Find::name, $new_name;
}


In that location there is a file named: testFile  with a space at the end of the name. For some reason i am unable to strip the space at the end of the file.
Avatar of ozo
ozo
Flag of United States of America image

did the rename return a true value or a false value?
what was $! after it returned?
ASKER CERTIFIED SOLUTION
Avatar of tel2
tel2
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial