[comp.lang.perl] debugger problems with pl 36.

russell@ccu1.aukuni.ac.nz (Russell J Fulton;ccc032u) (10/26/90)

I am a new perl user (we get perl about a week ago). I have written a small
perl program (included below) to put up new versions of software on our system.

All is well except that the debugger dies with a segmentation fault if
the test marked `# <<<< debugger dies' is true. i.e the target file does not
exist. If the debugger is not used program runs as expected.

I am on a SGI 4D/240 running irix 3.3.1. Perl is at patch level 36.

BTW this is my first perl program if any body can see better ways of doing
things or points of style please feel free to point them out!

#!/usr/local/bin/perl
#
# sc (Software Change) replaces an existing file in a directory.
#   If the old file was last modified more than 12 hours ago then it
#   is 'mv'ed to name.old before the new version is copied into the
#   directory. sc sets the mode of the new file to be the same as the old
#   and then writes an entry in a log file.

$LOGFILE = '>>test.log';

if ($#ARGV ne 2 ) {
    print "The sc command should have 3 arguments: the file name to be copied,\n";
    print "       the directory in which the public version is kept and\n";
    print "       a comment saying what has been changed for the log.\n";
    print " eg.   sc sc /usr/local/bin 'New version in perl!!!'\n";
    exit 1;
}

($source,$dest,$comment)=@ARGV;

@tmp = split(/\//,$source);  # get the file name
$fn = $tmp[$#tmp];
$target= $dest.'/'.$fn;

if (!  -r $source )   #does source exist ?
{
    print "$source can not be read!\n";
    exit 1;
}

if ( ! -w $target ) #does dest exist ?
{                                    # <<<< debugger dies (last line displayed)
    print "$target does not exist!\n";  
    print "Use install to put up new software.\n";
    exit 1;
}

@tstat = stat($target);
$t = time;

if ( $t - $tstat[9] > 43200 )		     # is existing file more than
   { system "mv $target $target.'.old'"; }   # 12 hours old?

system "cp $source $dest";

#$mode = $tstat[2];
chmod $tstat[2], $dest;
chown $tstat[5], $tstat[5], $dest;

@ctime = localtime($t);


open(LOGFILE);
print LOGFILE $ctime[3],'/',$ctime[4],'/',$ctime[5],' ',$ctime[2],':',
              $ctime[1],':',$ctime[3], ' ',$target,' ',$comment,"\n";
close(LOGFILE);

--