Skip to main content
added 45 characters in body
Source Link
user55518
user55518

The perl-way:

#!/usr/bin/perl

opendir(DIR,".") or die "$@:$!";
while ($in = readdir(DIR)) {
  next unless -f $in;
  ($out = $in) =~ s/[^a-zA-Z0-9._-]//g;
  warn "$@:$!" unless rename $in, $out;
}
closedir(DIR);

The regex filters onleonly a-zA-Z ... (could also be [:print:] for printable chars) as valid chars, there. There is no checking for empty target names.

The perl-way:

#!/usr/bin/perl

opendir(DIR,".") or die "$@:$!";
while ($in = readdir(DIR)) {
  next unless -f $in;
  ($out = $in) =~ s/[^a-zA-Z0-9._-]//g;
  warn "$@:$!" unless rename $in, $out;
}
closedir(DIR);

The regex filters onle a-zA-Z ... as valid chars, there is no checking for empty target names.

The perl-way:

#!/usr/bin/perl

opendir(DIR,".") or die "$@:$!";
while ($in = readdir(DIR)) {
  next unless -f $in;
  ($out = $in) =~ s/[^a-zA-Z0-9._-]//g;
  warn "$@:$!" unless rename $in, $out;
}
closedir(DIR);

The regex filters only a-zA-Z ... (could also be [:print:] for printable chars) as valid chars. There is no checking for empty target names.

Source Link
user55518
user55518

The perl-way:

#!/usr/bin/perl

opendir(DIR,".") or die "$@:$!";
while ($in = readdir(DIR)) {
  next unless -f $in;
  ($out = $in) =~ s/[^a-zA-Z0-9._-]//g;
  warn "$@:$!" unless rename $in, $out;
}
closedir(DIR);

The regex filters onle a-zA-Z ... as valid chars, there is no checking for empty target names.