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

Re: using switch

by Corion (Pope)
on Sep 29, 2005 at 13:05 UTC ( #496089=note: print w/ replies, xml ) Need Help??


in reply to using switch

Perl has no built-in switch statement. The Switch module should not be used. As you don't show any code and don't show what problem you are trying to solve, I can't help you further.

You might want to read some warnings on using Switch:


Comment on Re: using switch
Re^2: using switch
by sicone (Initiate) on Sep 29, 2005 at 16:02 UTC
    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
      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" }
      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://496089]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2014-10-31 05:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (214 votes), past polls