Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Perl 为什么交换机没有';不行?_Perl_Switch Statement_Mod Perl_Perl Data Structures - Fatal编程技术网

Perl 为什么交换机没有';不行?

Perl 为什么交换机没有';不行?,perl,switch-statement,mod-perl,perl-data-structures,Perl,Switch Statement,Mod Perl,Perl Data Structures,这个程序抛出一个错误。问题是我必须使用开关案例。如何在Perl中实现这一点 #use strict; #use warnings; my $input = print "Enter the number"; $input = <STDIN>; switch($input){ case "1" {print "UPC"} case "2" {print "ES"} case "3" {print "MS"} else {print "Enter the

这个程序抛出一个错误。问题是我必须使用
开关
案例
。如何在Perl中实现这一点

#use strict;
#use warnings;
my $input = print "Enter the number";
$input = <STDIN>;
switch($input){
    case "1" {print "UPC"}
    case "2" {print "ES"}
    case "3" {print "MS"}
    else {print "Enter the correct value"}
}
#严格使用;
#使用警告;
my$input=打印“输入号码”;
$input=;
开关($input){
案例“1”{打印“UPC”}
案例“2”{打印“ES”}
案例“3”{打印“MS”}
否则{print“输入正确的值”}
}
有点不同:

use feature "switch";

given ($foo) {
        when (/^abc/) { $abc = 1; }
        when (/^def/) { $def = 1; }
        when (/^xyz/) { $xyz = 1; }
        default { $nothing = 1; }
    }
您可以使用添加一个更传统的case语句,但正如robarl指出的那样,这是不推荐的

另外,永远不要注释掉
使用strict;使用警告作为修复问题的尝试

有点不同:

use feature "switch";

given ($foo) {
        when (/^abc/) { $abc = 1; }
        when (/^def/) { $def = 1; }
        when (/^xyz/) { $xyz = 1; }
        default { $nothing = 1; }
    }
您可以使用添加一个更传统的case语句,但正如robarl指出的那样,这是不推荐的


另外,永远不要注释掉
使用strict;使用警告作为修复问题的尝试

您需要导入交换机才能使用它:

use Switch;
然而,这一转变一直在进行。见这个问题:

此处讨论了一些备选方案(及其试验状态):

总之,如果您使用的是Perl>5.10.1,则可以将以下内容用于非弃用、非实验性的交换机:

use v5.10.1;
for ($var) {
    when (/^abc/) { $abc = 1 }
    when (/^def/) { $def = 1 }
    when (/^xyz/) { $xyz = 1 }
    default { $nothing = 1 }
}

您需要导入交换机才能使用它:

use Switch;
然而,这一转变一直在进行。见这个问题:

此处讨论了一些备选方案(及其试验状态):

总之,如果您使用的是Perl>5.10.1,则可以将以下内容用于非弃用、非实验性的交换机:

use v5.10.1;
for ($var) {
    when (/^abc/) { $abc = 1 }
    when (/^def/) { $def = 1 }
    when (/^xyz/) { $xyz = 1 }
    default { $nothing = 1 }
}

你的标题是什么意思?对于将来的参考,说明你收到的错误消息通常是有帮助的。你的标题是什么意思?对于将来的参考,说明你收到的错误消息通常是有帮助的。它不是不推荐的,但它是实验性的。它不是不推荐的,但它是实验性的。