Skip to content

Instantly share code, notes, and snippets.

@siracusa
Created August 16, 2014 16:29
Show Gist options
  • Save siracusa/5720437eeedec02a7171 to your computer and use it in GitHub Desktop.
Save siracusa/5720437eeedec02a7171 to your computer and use it in GitHub Desktop.
Larry Wall's file renamer, slightly modified
#!/usr/bin/perl
use strict;
use warnings;
die "Usage: rename <expression> <files>\n" unless (@ARGV >= 2);
my $op = eval 'sub { ' . shift . ' }'; # crazily dangerous - type carefully!
die $@ if $@;
for (@ARGV) {
my $was = $_;
$op->($_);
unless($was eq $_) {
rename($was, $_) or warn "Couldn't rename $was -> $_ - $!\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment