Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.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而STDIN。。。。Don';我还是不明白_Perl - Fatal编程技术网

Perl而STDIN。。。。Don';我还是不明白

Perl而STDIN。。。。Don';我还是不明白,perl,Perl,我不明白。这是,但不适用于函数 else{ print ("Falsch. Bitte nochmals geben Sie es!\n"); $name = <STDIN>; chomp ($name); while ($name ne $fullname){ print ("Falsch. Bitte nochmals geben Sie es!\n"); $name = <STDIN>;

我不明白。这是,但不适用于函数

else{
    print ("Falsch. Bitte nochmals geben Sie es!\n");
    $name = <STDIN>;
    chomp ($name);
    while ($name ne $fullname){
        print ("Falsch. Bitte nochmals geben Sie es!\n");
        $name = <STDIN>;
        chomp ($name);
        if ($sceret ne $sceretpassword){
            print ("Falsch Passwort!\n");
            $sceret = <STDIN>;
            chomp ($sceret);
        }
    }
}
my $fullname = "Markus Buergi";
my $sceretpassword = "Alpiq";
my $get_name = "Hello, your Name is ";
my $get_password = "Password is correct!";
my $wrong_name = "Wrong, Name again: ";
my $wrong_password = "Wrong, Password: ";
else{
打印(“Falsch.bite nochmals geben Sie!\n”);
$name=;
chomp($name);
而($name ne$fullname){
打印(“Falsch.bite nochmals geben Sie!\n”);
$name=;
chomp($name);
如果($sceret ne$sceret密码){
印刷品(“马兜铃草!\n”);
$sceret=;
chomp($sceret);
}
}
}
嗯,我该怎么办呢?请帮帮我。非常感谢


您的代码做了一些奇怪的事情

在“name”与“fullname”不匹配时循环

但是,在您请求密码之前,请先测试密码:

if ($sceret ne $sceretpassword){
    print ("Falsch Passwort!\n");
    $sceret = <STDIN>;
    chomp ($sceret);
}
if($sceret ne$sceret密码){
印刷品(“马兜铃草!\n”);
$sceret=;
chomp($sceret);
}
这在技术上是可行的,因为如果你:

  • 使用正确的密码登录-将失败
  • 然后再次登录-以前的密码仍将被“存储”,并且可以使用
这有点奇怪

也许你的意思是:

while ($name ne $fullname
    or $sceret ne $sceretpassword ) {
    print ("Incorrect login\n");
    print "name:\n";
    $name = <STDIN>;
    chomp ($name);
    print "Password:\n";
    $sceret = <STDIN>;
    chomp ($sceret);
}
while($name ne$fullname)
或$sceret ne$sceret密码){
打印(“不正确的登录\n”);
打印“名称:\n”;
$name=;
chomp($name);
打印“密码:\n”;
$sceret=;
chomp($sceret);
}
这将继续循环,直到有人获得正确的名称和密码组合

德国联邦银行(Für deutscheÜbersetzung siehe unten)。 您可以使用
while
循环重复,直到满足条件

在向用户询问密码之前,您检查了密码是否正确

这里使用了两个循环。在另一个答案中,只使用了一个。它较短,但您需要
next
在中间再次询问用户是否有任何数据错误

print "Enter name: ";
$name = <STDIN>;
chomp $name;

# if the name is correct the first time, this won't run
while ($name ne $fullname){
    print "Wrong. Enter again: ";
    $name = <STDIN>;
    chomp $name;
}
print "Enter password: ";
$secret = <STDIN>;
chomp $secret;
while ($secret ne $secretpassword){
    print "Wrong. Enter again: ";
    $secret = <STDIN>;
    chomp $secret;
}
# if you are here, the name and password are correct

当你在这里的时候,你就可以看到你在那里

你有一本书。当你在这里时,你会感到很高兴。在安徒生的蚂蚁草中,有一种叫艾恩马尔·贝努茨特的植物。你是库尔泽,下一个是布劳克斯特,我是弗雷根,我是弗雷根

print "Name eingeben: ";
$name = <STDIN>;
chomp $name;

# wenn der Name richtig ist, wird die Schleife gar nicht ausgefuehrt
while ($name ne $fullname){
    print "Falscher Name. Nochmal: ";
    $name = <STDIN>;
    chomp $name;
}
print "Passwort eingeben: ";
$secret = <STDIN>;
chomp $secret;
while ($secret ne $secretpassword){
    print "Falsches Passwort. Nochmal: ";
    $secret = <STDIN>;
    chomp $secret;
}
# wenn wir hier ankommen war beides richtig

非常感谢你的帮助!但我找到了一个好代码。它的功能很好

else{
    print ("Falsch. Bitte nochmals geben Sie es!\n");
    $name = <STDIN>;
    chomp ($name);
    while ($name ne $fullname){
        print ("Falsch. Bitte nochmals geben Sie es!\n");
        $name = <STDIN>;
        chomp ($name);
        if ($sceret ne $sceretpassword){
            print ("Falsch Passwort!\n");
            $sceret = <STDIN>;
            chomp ($sceret);
        }
    }
}
my $fullname = "Markus Buergi";
my $sceretpassword = "Alpiq";
my $get_name = "Hello, your Name is ";
my $get_password = "Password is correct!";
my $wrong_name = "Wrong, Name again: ";
my $wrong_password = "Wrong, Password: ";
第二个名字是正确的,更进一步
else{
打印$U错误的名称;
$name=;
chomp($name);
而($name ne$fullname){
打印$U错误的名称;
$name=;
chomp($name);
}
打印$get\u name、$name、“\n”;
做{
打印$U错误的密码;
$sceret=;
chomp($sceret);
}
直到($sceret eq$sceret password);
打印$get_密码“\n”;
出口
}

它的功能看起来不错。

Deine Frage是nicht klar。你的问题不清楚。你想一直询问用户的姓名和密码,直到他们正确为止吗?我的留言是:“Geben Sie deine Passwort”和“Geben Sie deine name”。这是我的语法。(德语语法有点错误?@Arc676显然,OP的德语和英语都不流利。我们不是在校对。SE;)我把你的问题转回到混合/德语版本。这样很好。代码中不必有英文文本。但下次请将代码作为代码发布,而不是截图。它很漂亮,色彩丰富,但我们无法复制和运行它@辛巴布谢谢你的欢迎。欢迎使用和stack overflow perl标记,我感觉很好!之后我需要一直询问堆栈溢出。堆栈溢出非常有用。快乐。:-)谢谢太好了!如果名称正确,则密码错误。但是不要忘记密码,请进一步询问。名字是正确的,不要重复。我确实进一步尝试了。我发现德语和英语的混合让人难以置信地难以理解。如果你把英语和德语分为两部分,先用英语写出完整的答案,然后用“Deutsch siehe unten”开头,也许你会更好地理解这个答案。当你觉得OP在用英语拼凑时,尝试用一种通用语言给出答案是很好的,但请记住,其他人也应该从内容中受益。我曾经有过这样的情况,我想用德语解释,但我决定不这样做,因为它太乱了。所以它不是为这个而设计的。聊天也许会有帮助。辛巴基,我明白!我要把德语改成英语。没问题。我希望有帮助。谢谢。:-)@辛巴布只是出于好奇,你会说德语吗?如果你愿意,你可以编辑我的答案,可能会改进单词的选择。我自己一点也不流利。马库斯:我想他指的是我的答案,不是你原来的问题。@马库斯:是的,我指的是答案。你的问题是英文的,没关系。很明显,你也不是德国人
else{
    print ("Falsch. Bitte nochmals geben Sie es!\n");
    $name = <STDIN>;
    chomp ($name);
    while ($name ne $fullname){
        print ("Falsch. Bitte nochmals geben Sie es!\n");
        $name = <STDIN>;
        chomp ($name);
        if ($sceret ne $sceretpassword){
            print ("Falsch Passwort!\n");
            $sceret = <STDIN>;
            chomp ($sceret);
        }
    }
}
my $fullname = "Markus Buergi";
my $sceretpassword = "Alpiq";
my $get_name = "Hello, your Name is ";
my $get_password = "Password is correct!";
my $wrong_name = "Wrong, Name again: ";
my $wrong_password = "Wrong, Password: ";