Example 1

#!/usr/local/bin/perl
#
## rename series of frames
#
#if ($#ARGV != 3) {
    print "usage: rename old new start stop\n";
    exit;
}

$old = $ARGV[0];
$new = $ARGV[1];
$start = $ARGV[2];
$stop = $ARGV[3];

for ($i=$start; $i <= $stop; $i++) {

    $num = $i;
    if($i<10) { $num = "00$i"; }
    elsif($i<100) { $num = "0$i"; }

    $cmd = "mv $old.$num $new.$num";
    print $cmd."\n";
    if(system($cmd)) { print "rename failed\n"; }
}

Example 2

#!/usr/local/bin/perl
#
# change all occurances of a string in a file to another string
#

if ($#ARGV != 3) {
    print "usage: chstring oldfile newfile oldstring newstring\n";
    exit;
}

$oldfile = $ARGV[0];
$newfile = $ARGV[1];
$old = $ARGV[2];
$new = $ARGV[3];

open(OF, $oldfile);
open(NF, ">$newfile");

# read in each line of the file
while ($line = ) {
    $line =~ s/$old/$new/;
    print NF $line;
}

close(OF);
close(NF);

Example 3

#!/usr/local/bin/perl
#
# search for a file in all subdirectories
#
if ($#ARGV != 0) {
    print "usage: findfile filename\n";
    exit;
}

$filename = $ARGV[0];

# look in current directory
$dir = `pwd`;
chop($dir);
&searchDirectory($dir);

sub searchDirectory {
    local($dir);
    local(@lines);
    local($line);
    local($file);
    local($subdir);

    $dir = $_[0];

    # check for permission
    if(-x $dir) {

	# search this directory
	@lines = `cd $dir; ls -l | grep $filename`;
	foreach $line (@lines) {
	    $line =~ /\s+(\S+)$/;
	    $file = $1;
	    print "Found $file in $dir\n";
	}
	
	# search any sub directories
	@lines = `cd $dir; ls -l`;
	foreach $line (@lines) {
	    if($line =~ /^d/) {
		$line =~ /\s+(\S+)$/;
		$subdir = $dir."/".$1;
		&searchDirectory($subdir);
	    }
	}
    }
}