You might want to try a search on CPAN, there is a switch module there...

http://search.cpan.org/search?query=switch&mode=all


Here is some sample code from the perldoc:
=====

use Switch;
        switch ($val) {

                case 1          { print "number 1" }
                case "a"        { print "string a" }
                case [1..10,42] { print "number in list" }
                case (@array)   { print "number in list" }
                case /\w+/      { print "pattern" }
                case qr/\w+/    { print "pattern" }
                case (%hash)    { print "entry in hash" }
                case (\%hash)   { print "entry in hash" }
                case (\&sub)    { print "arg to subroutine" }
                else            { print "previous case not true" }
        }


=====

Rob

-----Original Message-----
From: Mark Goland [mailto:[EMAIL PROTECTED]]
Sent: Friday, October 11, 2002 3:20 PM
To: [EMAIL PROTECTED]
Subject: switch


Hi guys,

I am trying to implement a switch statment in perl. I have tryed doing it 2
way's. For some reason my comparison statments are not working can some one
please look over my code and see if they can point me on the right track ??

Thanx in advance,
Mark

Solution 1:

while( ( $Remainder = ($P_lenght%16065) ) != 0 )
{
  print "\a size you gave is not multiple of cylenders\n";
 print "round (U)p (D)own (R)enter ?"; $Ans=<>;
# chomp ($Ans);
print $Ans;
for ($where){
/u/ && do{print "u\n";};
/d/ && do{print "d\n";};
# default
print "enter partition length        : ";
chomp ( $P_lenght=<> );


}
}
_exit 0;

solution 2:

while( ( $Remainder = ($P_lenght%16065) ) != 0 )
{
  print "\a size you gave is not multiple of cylenders\n";
 print "round (U)p (D)own (R)enter ?"; $Ans=<>;
# chomp ($Ans);
print $Ans;
if( $Ans =~ /u/i ){
$P_lenght = ($P_lenght - $Remainder+$CYLLENGTH);
}
elsif( $Ans =~ /d/i){
$P_lenght-=$Remainder;
}
# default
else{
print "enter partition length        : "; chomp ( $P_lenght=<> );
}


}

_exit 0;




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

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

Reply via email to