First off - always use strictures (use strict; use warnings;).

Perl initializes everything for you (to undef mostly) so if you don't have a real value to assign to a variable at declaration time don't assign anything. Combined with use warnings; that often gives early warning about logic errors.

Declare variables as late as possible so the scope over which they are used is clearer.

Uber points for checking the result of your opens, but you should use the three parameter open for extra safety and clarity.

Don't use & for calling subroutines - it's generally not needed and often doesn't do what you think.

Don't use global variables in subs (askname for example) - it's often unclear where variables are altered if you do that sort of thing leading to difficult to debug problems. Your name fetching loop may be better as:

my $playername; until ($playername) { print "What is your player's name?: "; chomp($playername = <STDIN>); }

Apart from a reprise of the globals and calling convention issues, clipcalc only processes the first line of the log file. It would be better written as:

while (<LOGFILE>) { $clipsobt++ if /\bclip\b/i; }

Perl is environmentally friendly - it saves trees

In reply to Re: Error Problem by GrandFather
in thread Error Problem by DontPanic42

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.