Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Text Based Perl Game

by Athanasius (Monsignor)
on Dec 18, 2013 at 03:45 UTC ( #1067584=note: print w/ replies, xml ) Need Help??


in reply to Text Based Perl Game

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,


Comment on Re: Text Based Perl Game
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1067584]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (9)
As of 2014-12-25 23:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (163 votes), past polls