Instantly share code, notes, and snippets.

Embed
What would you like to do?
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