Home Perl

#!/usr/bin/perl

#-------------------------------------------------- 

# Usage examples

# remove spaces from all files in current directory 
#  's/ //g' *

# remove single quotes 
# "s/['"]//g" *

#prefix all files with . 
# 's/(.+)/.$1/' *

#Change file extensions from .txt .old 
# 's/txt$/old/' * 
#--------------------------------------------------

($regexp = shift @ARGV) || die "Usage: see examples in script\n";

if (!@ARGV) { 
	@ARGV = <STDIN>; 
	chomp(@ARGV); 
}

foreach $_ (@ARGV) { 
	$oldName = $_; 
	eval $regexp; 
	die $@ if $@; 
	rename($oldName, $_) unless $oldName eq $_; 
}

exit(0);