develooper Front page | perl.beginners | Postings from February 2002

Re: Does Perl have "Case" Statements?

Thread Previous
From:
Michael Kelly
Date:
February 28, 2002 13:50
Subject:
Re: Does Perl have "Case" Statements?
Message ID:
B8A3E625.7E41%jedimike@mac.com
On 2/28/02 1:41 PM, Chris <chris@candp-ent.com> wrote:

> I have been looking in the Learning Perl book, and cannot find it.
> 
> I am sure that it is just a terminology thing.
> 
> In VB {Yeah the old VB again :P) I could do:
> 
> Select Case $Junk
> Case 1
> Do Something
> Case 2
> Do Something
> Case 3
> Do Something
> Case 4
> Do Something
> End Select
> 
> Does Perl have something similar to where I do not have to have one
> humongous IF statement?

Nope, but you have elsifs:

if ($Junk eq '1'{
    dostuff();
}
elsif ($Junk eq '2'){
    dostuff();
}
elsif ($Junk eq '3'){
    dostuff();
}
elsif ($Junk eq '4'){
    dostuff();
}

A little longer that a case, but it's better than nested ifs.

-- 
Michael


Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About