home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2245 < prev    next >
Internet Message Format  |  1990-12-28  |  949b

  1. From: tchrist@convex.COM (Tom Christiansen)
  2. Newsgroups: alt.sources
  3. Subject: Re: Neat utility to convert uppercase filenames
  4. Message-ID: <110060@convex.convex.com>
  5. Date: 8 Dec 90 03:40:18 GMT
  6.  
  7. Here's one version of rename, a generic utility to 
  8. perform infinite contortions on your filenames.  It's
  9. surely more powerful than anything of its ilk I've
  10. ever seen before.
  11.  
  12. --tom
  13.  
  14. #!/usr/bin/perl
  15. #
  16. # rename script examples from lwall:
  17. #       rename 's/\.orig$//' *.orig
  18. #       rename 'y/A-Z/a-z/ unless /^Make/' *
  19. #       rename '$_ .= ".bad"' *.f
  20. #       rename 'print "$_: "; s/foo/bar/ if <stdin> =~ /^y/i' *
  21. #
  22. # shows good use of eval operator
  23.  
  24. $op = shift;
  25. for (@ARGV) {
  26.     $was = $_;
  27.     eval $op;
  28.     die $@ if $@;
  29.     rename($was,$_) unless $was eq $_;
  30. }
  31.  
  32. --
  33. Tom Christiansen        tchrist@convex.com    convex!tchrist
  34. "With a kernel dive, all things are possible, but it sure makes it hard
  35.  to look at yourself in the mirror the next morning."  -me
  36.