EDIT: Dealt with one error message, still getting a couple others.
Code:
#!usr/bin/perl
# switchexperiment.perl
use warnings;
use strict;
my $variable=<STDIN>;
my $word;
chomp $variable;
switch ($variable){
case=1 {
$word="One";
}
case=2 {
$word="Two";
}
case=3 {
$word="Three";
}
else {
$word="Zip";
}
}
print $word;
Originally Posted by Error
syntax error at C:\Program Files\xampp\htdocs\Pages\Scripts\switchexperiment.perl line 11, near "){"
Execution of C:\Program Files\xampp\htdocs\Pages\Scripts\switchexperiment.perl aborted due to compilation errors.
Last edited by Mr Initial Man; 10-16-2006 at 01:07 PM.
Can't locate Switch.pm in @INC (@INC contains: C:/Perl/lib C:/Perl/site/lib .) at C:\Program Files\xampp\htdocs\Pages\Scripts\switchexperiment.perl line 6.
BEGIN failed--compilation aborted at C:\Program Files\xampp\htdocs\Pages\Scripts\switchexperiment.perl line 6.
I would actually suggest that you update your version of Perl. The Switch module is one of the core modules that comes prepackaged with Perl, but it is possible that you have an older release of Perl that did not include it.
If you do not want to install the latest version of Perl, then you will need to install this module. If you installed ActiveState's ActivePerl, then you can use their Perl Package Manager; if you compiled Perl on your machine, then you should use the CPAN module.
F.Y.I. The switch module is now deprecated. There is now the given-when statement which is much more powerful. Or you can simply is the if-else control structure.
Bookmarks