I read with great interest about one user's habit of copying old small scripts into a single text file for storage. I decided to make a small script to do it for me.

My question is this: although I have been doing perl for a few years now, a lot of what I read here is way over my head. I use perl every single day, yet I never seem to "progress" to the point of things like writing my own modules, etc.

My worry is that somehow I am missing something - that the code I write could be "better" if I only learned all the stuff that usually flies over my head in here.

Anyone agree?

Also, here is an example - the script I wrote to add to that graveyard file! Shows how I still do things the "beginner" way.

#!/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); } }


What does this little button do . .<Click>; "USER HAS SIGNED OFF FOR THE DAY"

In reply to Missing Something by tame1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.