Created
August 16, 2014 16:29
-
-
Save siracusa/5720437eeedec02a7171 to your computer and use it in GitHub Desktop.
Larry Wall's file renamer, slightly modified
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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