Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: using switch

by sicone (Initiate)
on Sep 29, 2005 at 16:02 UTC ( #496155=note: print w/ replies, xml ) Need Help??


in reply to Re: using switch
in thread using switch

i WAS THINKING OF USING IT IN A RPG IM WORKING ON, WELL IT'S A PROJECT I USING TO LEARN PERL. I WAS GOING TO USE THE SWITCH MODULE FOR THINGS LIKE MOVEMENT. ROUGH EXAMPLE CODE NOT TESTED.

USE SWITCH; SUB DIRECTIONS { WHILE { $DIRECTIONS= (<STDIN>); CHOMP $DIRECTIONS $DIRECTIONS =~ TR/A-Z/a-z/; SWITCH { CASE 'NORTH' {PRINT "$HERONAME HAS LEFT NORTH"} CASE 'SOUTH' {PRINT "$HERONAME HAS LEFT SOUTH"} CASE 'EAST' {PRINT "$HERONAME HAS LEFT EAST"} CASE 'WEST' {PRINT "$HERONAME HAS LEFT WEST"} } } }
BASICALY THATS WHAY IM TRYING TO DO...BASICALY


Comment on Re^2: using switch
Download Code
Re^3: using switch
by sgifford (Prior) on Sep 29, 2005 at 16:10 UTC
    Just use several if statements:
    if ($DIRECTIONS eq 'NORTH') { print "$HERONAME HAS LEFT NORTH\n" } elsif ($DIRECTIONS eq 'SOUTH') { print "$HERONAME HAS LEFT SOUTH\n" } elsif ($DIRECTIONS eq 'EAST') { print "$HERONAME HAS LEFT EAST\n" } elsif ($DIRECTIONS eq 'WEST') { print "$HERONAME HAS LEFT WEST\n" }
Re^3: using switch
by castaway (Parson) on Sep 29, 2005 at 16:11 UTC
    Sounds like you just need to use dispatching. i.e. make a hash which contains the possible commands/directions as keys, and has strings to output as values. (Or probably more useful, has coderefs as values to be run)

    C.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2014-04-20 14:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls