This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
avoid error in IO::Socket::INET when given an unknown service name
[perl5.git] / eg / relink
CommitLineData
9f68db38 1#!/usr/bin/perl
00bf170e
LW
2'di';
3'ig00';
4#
79072805 5# $RCSfile: relink,v $$Revision: 4.1 $$Date: 92/08/07 17:20:29 $
00bf170e
LW
6#
7# $Log: relink,v $
9f68db38
LW
8
9($op = shift) || die "Usage: relink perlexpr [filenames]\n";
10if (!@ARGV) {
00bf170e
LW
11 @ARGV = <STDIN>;
12 chop(@ARGV);
9f68db38
LW
13}
14for (@ARGV) {
15 next unless -l; # symbolic link?
16 $name = $_;
17 $_ = readlink($_);
18 $was = $_;
19 eval $op;
20 die $@ if $@;
21 if ($was ne $_) {
22 unlink($name);
23 symlink($_, $name);
24 }
25}
00bf170e
LW
26##############################################################################
27
28 # These next few lines are legal in both Perl and nroff.
29
30.00; # finish .ig
31
32'di \" finish diversion--previous line must be blank
33.nr nl 0-1 \" fake up transition to first page again
34.nr % 0 \" start at page 1
35';<<'.ex'; #__END__ ############# From here on it's a standard manual page ############
36.TH RELINK 1 "July 30, 1990"
37.AT 3
38.SH LINK
39relink \- relinks multiple symbolic links
40.SH SYNOPSIS
41.B relink perlexpr [symlinknames]
42.SH DESCRIPTION
43.I Relink
44relinks the symbolic links given according to the rule specified as the
45first argument.
46The argument is a Perl expression which is expected to modify the $_
47string in Perl for at least some of the names specified.
48For each symbolic link named on the command line, the Perl expression
49will be executed on the contents of the symbolic link with that name.
50If a given symbolic link's contents is not modified by the expression,
51it will not be changed.
52If a name given on the command line is not a symbolic link, it will be ignored.
53If no names are given on the command line, names will be read
54via standard input.
55.PP
56For example, to relink all symbolic links in the current directory
57pointing to somewhere in X11R3 so that they point to X11R4, you might say
58.nf
59
60 relink 's/X11R3/X11R4/' *
61
62.fi
63To change all occurences of links in the system from /usr/spool to /var/spool,
64you'd say
65.nf
66
67 find / -type l -print | relink 's#/usr/spool#/var/spool#'
68
69.fi
70.SH ENVIRONMENT
71No environment variables are used.
72.SH FILES
73.SH AUTHOR
74Larry Wall
75.SH "SEE ALSO"
76ln(1)
77.br
78perl(1)
79.SH DIAGNOSTICS
80If you give an invalid Perl expression you'll get a syntax error.
81.SH BUGS
82.ex