Things that I learnt the hard way are humbly offered for your consideration.

Always use warnings; then eliminate any that show up. They are problems waiting to happen.

use strict; think about what variables you are made to define, why and when they are needed;

Find a code layout standard that suits you and then stick with it. The structure so revealed will help you understand your thought processes and show you where you perhaps need to rewrite.

If the code looks clumsy then it can probably be written better. I would write (undef,undef,undef,undef,undef,undef,$wday,undef,undef) = localtime(time); until I found that this should be written $wday = (localtime)[6]; and write code that read lines and assembled paragraphs until I understood
{ local $/ = ""; $header = <STDIN>; }
Always bear in mind the richness that is CPAN. Don't reinvent; but reuse, recycle, or adapt.

Replies are listed 'Best First'.
RE: Hard Lessons
by turnstep (Parson) on Jun 10, 2000 at 02:14 UTC

    Or even just

    local $/; $header = <STDIN>;
    or perhaps
    local $/,$header=<STDIN>;
    TMTOWTDI :)

      i'm not so sure about this. my will initialize a variable to undef (lexical scoping), but i don't think that using local on a variable does anything but introduce dynamic scoping of the variable for the enclosing block and contained subroutine calls. it is not (re-)initialized, as it would be for my.

      update: so, as turnstep proves in his response, i am incorrect. damn.

        Well, it does work, as local not only squirrels away the old global value, but sets it to undef for the loop. However, upon writing some example code, I noticed a strange difference between two global variables, $/ and $^T. Both mean something, and always have values (and are thus defined) at the start of a script. However, $/ gets set to undef when used with a local, while $^T gets set to "0". [Luckily, $/ does not get set to 0, or my examples would not work. :)] Anyone know why $^T acts like that? Here's the code, and the results. This is perl 5.005_03, FWIW.

        $MY = 1; $LOC = 1; { local $LOC; local $LOC2; local $/; local $^T; my $MY; my $MY2; printf "LOC defined: %s\n", defined $LOC ? "YES" : "NO"; printf "LOC2 defined: %s\n", defined $LOC2 ? "YES" : "NO"; printf "IRS defined: %s\n", defined $/ ? "YES" : "NO"; printf "TIME defined: %s\n", defined $^T ? "YES" : "NO"; printf "MY defined: %s\n", defined $MY ? "YES" : "NO"; printf "MY2 defined: %s\n", defined $MY2 ? "YES" : "NO"; print " LOC=$LOC, LOC2=$LOC2, TIME=$^T, IRS=$/, MY=$MY, MY2=$MY2\n" +; } print "AFTER LOOP:\n"; print " LOC=$LOC, LOC2=$LOC2, TIME=$^T, IRS=$/, MY=$MY, MY2=$MY2\n";

        Which produces:

        LOC defined: NO LOC2 defined: NO IRS defined: NO TIME defined: YES MY defined: NO MY2 defined: NO LOC=, LOC2=, TIME=0, IRS=, MY=, MY2= AFTER LOOP: LOC=1, LOC2=, TIME=960648360, IRS= , MY=1, MY2=