> -----Original Message-----
> From: Gajo Csaba [mailto:[EMAIL PROTECTED]]
> Sent: Monday, November 04, 2002 9:18 AM
> To: perl-beginners
> Subject: The basics of SWITCH
> 
> 
> Hi, I have a problem with SWITCH. I wrote this, I think 
> it's clear to anzone what it should do:
> 
> print "Type in a number 1-5: ";
> $s = <STDIN>;
> SWITCH;

Your label needs a colon, not a semicolon

SWITCH:

> {
>  if ($s == 1) { print "one\n"; last SWITCH; }
>  if ($s == 2) { print "two\n"; last SWITCH; }
>  if ($s == 3) { print "three\n"; last SWITCH; }
>  if ($s == 4) { print "four\n"; last SWITCH; }
>  if ($s == 5) { print "five\n"; last SWITCH; }
> }
> 
> And I get an error message saying "Label not found 
> for "last SWITCH" at line 11. <STDIN> chunk 1." (with line 
> 11 being the first line of the chunk)
> 
> So what's wrong?
> 
> Also, how can I do something like in bash, where I have 
> options 1), 2)... and also *). That is, how can I do that 
> *) thing? :)

Just put your default case before the closing brace:

    ...
    if ($s == 5) { print "five\n"; last SWITCH; }
    print "Default case";             # if no previous match
}

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to