【发布时间】:2014-05-10 19:29:38
【问题描述】:
如您所见,我想将第一次替换的结果存储在$enkel 中。我在if 的打印中使用了这个$enkel。
但是当我想在elsif 打印中使用这个$enkel 时,它没有任何价值。我实际上想在elsif 打印中同时使用$dubbel 和$enkel。
有没有办法让 Perl 将其永久存储在 $dubbel 中,以便可以在其他打印中使用?
if ($inputwoord =~ /((aa|uu|ee|oo)[^aeiour])$/) {
($enkel = $inputwoord) =~ s/([aueo])\1/$1/g;
print "$enkel$buig\n$inputwoord$gen\n$enkel$comp\n$enkel$compe\n$inputwoord$sup\n$inputwoord$supe\n";
}
elsif ($inputwoord =~ /[^aeiou][aeiou]([pktgnmlf])$/) {
($dubbel = $inputwoord) =~ s /([pktgnmlf]$)/$1$1/g;
print "$dubbel$buig\n$inputwoord$gen\n$dubbel$comp\n$dubbel$compe\n$inputwoord$sup\n$inputwoord$supe\n";
} # consonantgeminatie
【问题讨论】:
-
请格式化您的代码,以便我们理解并运行它。帮助我们为您提供帮助。
-
请不要将 cmets(如星号)添加到代码本身。代码应该独立存在,任何评论都应该在问题的文本中。重要的是我们可以看到你正在运行的代码
-
我猜你的程序顶部没有
use strict和use warnings?要么,要么你在开始时在一个块中定义你的所有变量。您必须始终拥有use strict和use warnings,并且应使用my声明变量,使其尽可能接近它们的第一个使用点。
标签: perl variables store substitution