Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.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中的continue语句时给出_Perl - Fatal编程技术网

perl中的continue语句时给出

perl中的continue语句时给出,perl,Perl,我当时在学习Perl。在那里,我知道当类似于开关盒时给出的。因此为了练习,我写了下面的脚本。现在我知道,break是when给定的中固有的,要想完成,我需要使用continue语句 当我给输入“甜蜜”时,它给输出“像真实的人一样”。不应将输出作为 "Honey just put your sweet lips on my lips\n We should just kiss like real people do" 代码如下: #!/usr/bin/perl use strict; use

我当时在学习Perl。在那里,我知道当类似于开关盒时给出的
。因此为了练习,我写了下面的脚本。现在我知道,
break
when
给定的
中固有的,要想完成,我需要使用
continue
语句

当我给输入“甜蜜”时,它给输出“像真实的人一样”。不应将输出作为

"Honey just put your sweet lips on my lips\n
We should just kiss like real people do" 
代码如下:

#!/usr/bin/perl
use strict;
use warnings;
use feature "switch";
my $choice = <STDIN>;
my $msg ="";
chomp($choice);
given(lc $choice){
    when('a'){
        $msg = "I had a thought, dear";
    }
    when('b'){
        $msg = "However scary";
    }
    when('c'){
        $msg = "About that night";
    }
    when('d'){
        $msg = "The bugs and the dirt";
    }
    when('e'){
        $msg = "Why were you digging?";
    }
    when('sweet'){
        $msg =  "Honey just put your sweet lips on my lips ";
        continue;
    }
    when('lips'){
        $msg = $msg."\nWe should just kiss like real people do";
    }
    default{
        $msg = "";
    }
}

#print($msg,"\n");
unless($msg eq "") {
    print($msg, "\n");
}else{
    print("Like real People do!\n");
}
#/usr/bin/perl
严格使用;
使用警告;
使用“开关”功能;
我的$choice=;
我的$msg=“”;
chomp($choice);
给定(lc$选择){
当('a'){
$msg=“我有一个想法,亲爱的”;
}
何时('b'){
$msg=“无论多么可怕”;
}
当('c'){
$msg=“关于那天晚上”;
}
何时('d'){
$msg=“虫子和污垢”;
}
何时('e'){
$msg=“你为什么要挖?”;
}
什么时候(“甜”){
$msg=“亲爱的,把你甜蜜的嘴唇放在我的嘴唇上”;
继续;
}
什么时候(‘嘴唇’){
$msg=$msg。“\n我们应该像真人一样接吻”;
}
违约{
$msg=”“;
}
}
#打印($msg,“\n”);
除非($msg eq“”){
打印($msg,“\n”);
}否则{
打印(“像真人一样!\n”);
}
[请注意,smartmatching功能是实验性的,它被视为有一个坏的设计。通过扩展,交换机功能也是如此,因为它使用smartmatching。应该避免这些。]

实际上,
$msg
包含空字符串

#/usr/bin/perl
严格使用;
使用警告;
使用功能qw(如开关);
my$choice=“sweet\n”;
chomp($choice);
我的$msg=“”;
给定(lc$选择){
# ...
何时('e'){
$msg=“你为什么要挖?”;
}
什么时候(“甜”){
$msg=“亲爱的,把你甜美的嘴唇放在我的嘴唇上\n”;
继续;
}
什么时候(‘嘴唇’){
$msg.=“我们应该像真人一样接吻”;
}
违约{
$msg=”“;
}
}

假设“>$msgNote,
switch
功能是实验性的,被认为有一个坏的设计说明,
fc
(而不是
lc
)应该用于不区分大小写的比较。在这里,lc只是用来转换成小写。即使我删除了它,也不会给出正确的输出。@Ikegami以下是我最喜欢的文档片段:”当
时,
的EXPR参数的确切作用很难精确描述,“规则太难理解,无法在这里描述。”…这是您(我们)关于该功能的官方文档。请阅读所有内容——这是“高度机密”“实验性的,它将被改变。我建议您继续使用它,尽管它看起来很酷,但请使用其他技术。@UzumakiSaptarshi您将其转换为小写的原因是进行不区分大小写的比较。为此,您应该使用
fc
,而不是
lc
。添加的解决方案。