#!/usr/bin/perl use strict; use warnings; package module; my $state = 1; my @exits = ("Major Motoko Kusanagi wishes you well!","Come back soon, + ya hear?","Bah, coward!","Go with God.","Stellaaaaaa!","Namo Kuan Yi +n."); sub welcome { print "Welcome to my game! Do you want to move:\n\n"; print "North?\n"; print "South?\n"; print "East?\n"; print "West?\n\n"; } sub movement { while ($state == 1) { welcome(); print "<120/120hps 50/50mana 100/100mvs> "; chomp(my $move = <STDIN>); if ($move =~ /^(north|south|east|west)$/i) { print "\nYou have moved $move.\n\n"; } elsif ($move =~ /^quit$/i) { print "\n$exits[rand @exits]\n\n"; $state = 0; } else { print "\nThat is not a valid option.\n\n"; } } } movement(); 1;
Okay, so I do everything I'm supposed to do, right? When I finally make a test script for it, and run it through perl -c, it actually executes the program, in addition to returning whether or not the syntax is ok.
After a bit of trial and testing of other things, looking through older modules, even looked in warning.pm, I finally figured out what the problem was:
I had left the invocation from the original script in, when I modified it to be a module! I took out the invocation movement(); and all was well.
So the lesson there is, sometimes the simplest things can trip you up, if you forget about them.
EDIT: Code updated, per ysth's recommendations.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sometimes, the simplest things will trip you up, if you forget about them
by merlyn (Sage) on Mar 21, 2005 at 05:16 UTC | |
|
Re: Sometimes, the simplest things will trip you up, if you forget about them
by ysth (Canon) on Mar 21, 2005 at 06:55 UTC | |
|
Re: Sometimes, the simplest things will trip you up, if you forget about them
by Anonymous Monk on Mar 21, 2005 at 10:16 UTC | |
by matra555 (Monk) on Mar 22, 2005 at 01:35 UTC | |
by merlyn (Sage) on Mar 22, 2005 at 01:41 UTC |