#!/usr/bin/perl # # grave - a program to consign a short perl script into the # 1linegraveyard.txt file. # usage - grave use strict; my $TEXTFILE = "/home/jrobiso2/perl_scripts/1linegraveyard.txt"; error("arguement") unless $ARGV[0]; my $PROG = $ARGV[0]; my $progref = read_file($PROG); add_file($progref); print "Added $PROG to $TEXTFILE\n"; unlink($PROG); exit(0); sub read_file { my @output; my $file = shift; open(FILE, "< $file") || die "Cannot open $file!: $!\n"; while() { push @output, $_; } close(FILE); return \@output; } sub add_file { my $dataref = shift; my @lines = @$dataref; open(GRAVE, ">> $TEXTFILE") || die "Cannot open $TEXTFILE for writing: $!\n"; print GRAVE "\#" x 75 . "\n"; print GRAVE "\# $PROG\n"; my($day,$month,$year) = (localtime)[3,4,5]; $month = $month + 1; $year = $year + 1900; my $date = "$month\/$day\/$year"; print GRAVE "\# consigned to the graveyard on $date\n"; foreach my $line (@lines) { print GRAVE "$line\n"; } print GRAVE "\# end of file $PROG\n"; print GRAVE "\#" x 75 . "\n\n"; close(GRAVE); } sub error { my $error = shift; if ($error eq "arguement") { print "Usage - grave \n"; exit(0); } else { print "Exiting from unknown error! \n"; exit(0); } }