diff options
author | Larry Wall <lwall@jpl-devvax.jpl.nasa.gov> | 1990-02-28 21:56:43 +0000 |
---|---|---|
committer | Larry Wall <lwall@jpl-devvax.jpl.nasa.gov> | 1990-02-28 21:56:43 +0000 |
commit | 9f68db38bddc39fbd37e57bf1751eaf7aac28e57 (patch) | |
tree | 8c581f83488d49a072fcad6fb1ebb946d74948df /eg | |
parent | ac58e20f744208e9bff2115708a2f1c4e2e2175f (diff) | |
download | perl-9f68db38bddc39fbd37e57bf1751eaf7aac28e57.tar.gz |
perl 3.0 patch #12 patch #9, continued
See patch #9.
Diffstat (limited to 'eg')
-rw-r--r-- | eg/relink | 24 | ||||
-rw-r--r-- | eg/rename | 11 | ||||
-rw-r--r-- | eg/travesty | 46 |
3 files changed, 78 insertions, 3 deletions
diff --git a/eg/relink b/eg/relink new file mode 100644 index 0000000000..2d8e5f6540 --- /dev/null +++ b/eg/relink @@ -0,0 +1,24 @@ +#!/usr/bin/perl + +($op = shift) || die "Usage: relink perlexpr [filenames]\n"; +if (!@ARGV) { + if (-t) { + @ARGV = <*>; + } + else { + @ARGV = <STDIN>; + chop(@ARGV); + } +} +for (@ARGV) { + next unless -l; # symbolic link? + $name = $_; + $_ = readlink($_); + $was = $_; + eval $op; + die $@ if $@; + if ($was ne $_) { + unlink($name); + symlink($_, $name); + } +} @@ -1,9 +1,14 @@ #!/usr/bin/perl ($op = shift) || die "Usage: rename perlexpr [filenames]\n"; -if ($#ARGV < 0) { - @ARGV = <stdin>; - chop(@ARGV); +if (!@ARGV) { + if (-t) { + @ARGV = <*>; + } + else { + @ARGV = <STDIN>; + chop(@ARGV); + } } for (@ARGV) { $was = $_; diff --git a/eg/travesty b/eg/travesty new file mode 100644 index 0000000000..7e6f983c7c --- /dev/null +++ b/eg/travesty @@ -0,0 +1,46 @@ +#!/usr/bin/perl + +while (<>) { + next if /^\./; + next if /^From / .. /^$/; + next if /^Path: / .. /^$/; + s/^\W+//; + push(@ary,split(' ')); + while ($#ary > 1) { + $a = $p; + $p = $n; + $w = shift(@ary); + $n = $num{$w}; + if ($n eq '') { + push(@word,$w); + $n = pack('S',$#word); + $num{$w} = $n; + } + $lookup{$a . $p} .= $n; + } +} + +for (;;) { + $n = $lookup{$a . $p}; + ($foo,$n) = each(lookup) if $n eq ''; + $n = substr($n,int(rand(length($n))) & 0177776,2); + $a = $p; + $p = $n; + ($w) = unpack('S',$n); + $w = $word[$w]; + $col += length($w) + 1; + if ($col >= 65) { + $col = 0; + print "\n"; + } + else { + print ' '; + } + print $w; + if ($w =~ /\.$/) { + if (rand() < .1) { + print "\n"; + $col = 80; + } + } +} |