feedback Tim Klein was [CLUE-Tech] removing spaces from filenames?

Dave Price davep at kinaole.org
Tue Nov 19 09:35:06 MST 2002


On Sun, Nov 17, 2002 at 04:18:11PM -0700, Timothy C. Klein wrote:
> 
> #!/usr/bin/perl
> 
> use strict;
> use warnings;
> 
> # Change these to set up the desired replacement
> my $glob_pat = "*";
> my $out_pat = " ";
> my $replace_pat = "_";
> 
> foreach my $file (glob "$glob_pat") {
> 	my $newfile = $file;
> $newfile =~ s/$out_pat/$replace_pat/;
> 	if (-e $newfile) {
> 		warn "Can't rename $file to $newfile: $newfile exists.\n";
> 	} elsif (rename $file, $newfile) {
> 		## Sucess, the work is already done.
> 	} else {
> 		warn "Rename of $file to $newfile failed: $!\n";
> 	}
> }

I needed to change the search line to:
$newfile =~ s/$out_pat/$replace_pat/g;

To get more than 1 space in the name ...

(wish it could recurse)

aloha,
dave




More information about the clue-tech mailing list