tame1 has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl # # grave - a program to consign a short perl script into the # 1linegraveyard.txt file. # usage - grave <progname> 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(<FILE>) { push @output, $_; } close(FILE); return \@output; } sub add_file { my $dataref = shift; my @lines = @$dataref; open(GRAVE, ">> $TEXTFILE") || die "Cannot open $TEXTFILE for writ +ing: $!\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 <progname>\n"; exit(0); } else { print "Exiting from unknown error! \n"; exit(0); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Missing Something
by davorg (Chancellor) on Feb 07, 2001 at 21:41 UTC | |
by stefan k (Curate) on Feb 07, 2001 at 22:02 UTC | |
|
Re: Missing Something
by arhuman (Vicar) on Feb 07, 2001 at 21:39 UTC | |
|
Re: Missing Something
by stefan k (Curate) on Feb 07, 2001 at 21:50 UTC | |
|
Re: Missing Something
by tadman (Prior) on Feb 08, 2001 at 05:55 UTC | |
|
Re: Missing Something
by magnus (Pilgrim) on Feb 07, 2001 at 21:47 UTC | |
|
Re: Missing Something
by mirod (Canon) on Feb 07, 2001 at 21:47 UTC | |
|
Re: Missing Something
by $code or die (Deacon) on Feb 07, 2001 at 22:51 UTC | |
|
Re: Missing Something
by dash2 (Hermit) on Feb 08, 2001 at 04:09 UTC | |
|
Re: Missing Something
by t'mo (Pilgrim) on Feb 10, 2001 at 03:31 UTC | |
|
Re: Missing Something
by wardk (Deacon) on Feb 07, 2001 at 23:41 UTC |