perl 3.0 patch #25 patch #19, continued
[p5sagit/p5-mst-13.2.git] / eg / rename
1 #!/usr/bin/perl
2 'di';
3 'ig00';
4 #
5 # $Header: rename,v 3.0.1.2 90/08/09 03:17:57 lwall Locked $
6 #
7 # $Log: rename,v $
8 # Revision 3.0.1.2  90/08/09  03:17:57  lwall
9 # patch19: added man page for relink and rename
10
11
12 ($op = shift) || die "Usage: rename perlexpr [filenames]\n";
13 if (!@ARGV) {
14     @ARGV = <STDIN>;
15     chop(@ARGV);
16 }
17 for (@ARGV) {
18     $was = $_;
19     eval $op;
20     die $@ if $@;
21     rename($was,$_) unless $was eq $_;
22 }
23 ##############################################################################
24
25         # These next few lines are legal in both Perl and nroff.
26
27 .00;                    # finish .ig
28  
29 'di                     \" finish diversion--previous line must be blank
30 .nr nl 0-1              \" fake up transition to first page again
31 .nr % 0                 \" start at page 1
32 ';<<'.ex'; #__END__ ############# From here on it's a standard manual page ############
33 .TH RENAME 1 "July 30, 1990"
34 .AT 3
35 .SH NAME
36 rename \- renames multiple files
37 .SH SYNOPSIS
38 .B rename perlexpr [files]
39 .SH DESCRIPTION
40 .I Rename
41 renames the filenames supplied according to the rule specified as the
42 first argument.
43 The argument is a Perl expression which is expected to modify the $_
44 string in Perl for at least some of the filenames specified.
45 If a given filename is not modified by the expression, it will not be
46 renamed.
47 If no filenames are given on the command line, filenames will be read
48 via standard input.
49 .PP
50 For example, to rename all files matching *.bak to strip the extension,
51 you might say
52 .nf
53
54         rename 's/\e.bak$//' *.bak
55
56 .fi
57 To translate uppercase names to lower, you'd use
58 .nf
59
60         rename 'y/A-Z/a-z/' *
61
62 .fi
63 .SH ENVIRONMENT
64 No environment variables are used.
65 .SH FILES
66 .SH AUTHOR
67 Larry Wall
68 .SH "SEE ALSO"
69 mv(1)
70 .br
71 perl(1)
72 .SH DIAGNOSTICS
73 If you give an invalid Perl expression you'll get a syntax error.
74 .SH BUGS
75 .I Rename
76 does not check for the existence of target filenames, so use with care.
77 .ex