slitaz-dev-tools annotate baba-scripts/rename.pl @ rev 227

tazwikiss: typo in wkp_Rss.sh
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Apr 02 14:04:07 2014 +0000 (2014-04-02)
parents
children
rev   line source
postmaster@96 1 #! /usr/bin/perl
postmaster@96 2 $testmode = 0; #false
postmaster@96 3 if ($ARGV[0] eq '-t') {
postmaster@96 4 $testmode = 1; #true
postmaster@96 5 shift;
postmaster@96 6 }
postmaster@96 7 ($regexp = shift @ARGV) || die "Usage: rename [-t] perlexpr [filenames]\n-t : option to test action (nothing really done)\n";
postmaster@96 8 if (!@ARGV) {
postmaster@96 9 @ARGV = <STDIN>;
postmaster@96 10 chomp(@ARGV);
postmaster@96 11 }
postmaster@96 12 print "Test mode\n" if ($testmode);
postmaster@96 13 foreach $_ (@ARGV) {
postmaster@96 14 $old_name = $_;
postmaster@96 15 eval $regexp;
postmaster@96 16 die $@ if $@;
postmaster@96 17 unless ($old_name eq $_) {
postmaster@96 18 print "$old_name -> $_\n";
postmaster@96 19 rename($old_name, $_) unless $testmode;
postmaster@96 20 }
postmaster@96 21 }
postmaster@96 22 exit(0);