Hello spoonman2525, and welcome to the Monastery!

A few further comments:

  1. Anonymous Monk stole my thunder on this one, but definitely consider giving each lexical variable the smallest possible scope. For example, instead of one $command declared at the head of the script (thereby making it effectively global, despite its being declared with my), declare it each time it’s needed:

    sub mainMenu { ... chomp (my $command = <STDIN>); ...
  2. Also consider using lexical filehandles: open (my $OUT, '+>', DATAFILEOUT).

  3. The pragma use constant QUIT => 5; is actually implemented as a function, which is why you are getting warnings like this:

    Constant subroutine main::QUIT redefined at C:/Perl/Strawberry/strawbe +rry-perl-5.18.1.1-32bit-portable/perl/lib/constant.pm line 140.

    In other words, anything declared with use constant is a global. It’s better to give each constant a unique name:

    use constant QUIT_COMPUTER_COMMAND => 5;
  4. Reserve die for error conditions. For normal termination, prefer exit.

  5. In Perl, it’s really not necessary to define constants for TRUE and FALSE, and it’s certainly not necessary to name them explicitly when testing. For example, in sub bedroomCommand, it would be simpler to write:

    if ($light) { ... } else { ... }
  6. Familiarise yourself with Perl’s handy statement modifiers (see perlsyn). Then, instead of this (from sub loadGame):

    while (<$IN>) { chomp ($loadArray[$counter] = $_); $counter++; }

    you can write a single line, like this:

    chomp($loadArray[$counter++] = $_) while <$IN>;

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


In reply to Re: Text Based Perl Game by Athanasius
in thread Text Based Perl Game by spoonman2525

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.