Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/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 - Fatal编程技术网

Perl计算器读入数字不会进行计算

Perl计算器读入数字不会进行计算,perl,Perl,我的简单计算器程序有问题。它没有使用我的if语句执行计算:它直接转到else #!/usr/bin/perl print "enter a symbol operation symbol to and two numbers to make a calculation"; chomp($input = <>); if ($input eq '+') { $c = $a + $b; print $c; } elsif ($input eq '-') { $c = $a

我的简单计算器程序有问题。它没有使用我的
if
语句执行计算:它直接转到
else

#!/usr/bin/perl

print "enter a symbol operation symbol to and two numbers to make a calculation";

chomp($input = <>);

if ($input eq '+') {
  $c = $a + $b;
  print $c;
}
elsif ($input eq '-') {
  $c = $a - $b;
  print $c;
}
elsif ($input eq '*') {
  $c = $a * $b;
  print $c;
}
elsif ($input eq '/') {
  $c = $a / $b;
  print $c;
}
elsif ($input eq '%') {
  $c = $a % $b;
  print $c;
}
elsif ($input eq '**') {
  $c = $a**$b;
  print $c;
}
elsif ($input eq 'root') {
  $c = sqrt($a);
  $c = sqrt($b);
  print $c;
}
else {
  print " you messed up" . "$input" . "$a" . "$b";
}
#/usr/bin/perl
打印“输入一个符号操作符号和两个数字进行计算”;
chomp($input=);
如果($input eq'+')){
$c=$a+$b;
打印$c;
}
elsif($input eq'-')){
$c=$a-$b;
打印$c;
}
elsif($input eq'*')){
$c=$a*$b;
打印$c;
}
elsif($input eq'/')){
$c=$a/$b;
打印$c;
}
elsif($input eq“%”){
$c=$a%$b;
打印$c;
}
elsif($input eq'**')){
$c=$a**$b;
打印$c;
}
elsif($input eq‘root’){
$c=sqrt($a);
$c=sqrt($b);
打印$c;
}
否则{
打印“你搞砸了”。“$input”。“$a”。“$b”;
}

您在
输入之前的第一个条件中忘记了“$”符号

if($input eq '+'){
$c = $a + $b;
print $c;

您在
输入之前的第一个条件中忘记了“$”符号:

if($input eq '+'){
$c = $a + $b;
print $c;

您在
输入之前的第一个条件中忘记了“$”符号:

if($input eq '+'){
$c = $a + $b;
print $c;

您在
输入之前的第一个条件中忘记了“$”符号:

if($input eq '+'){
$c = $a + $b;
print $c;
此外,除非您精通Perl,否则我建议在顶部使用“use strict”和“use warnings”

此外,除非您精通Perl,否则我建议在顶部使用“use strict”和“use warnings”

此外,除非您精通Perl,否则我建议在顶部使用“use strict”和“use warnings”


此外,除非您精通Perl,否则我建议在顶部使用“use strict”和“use warnings”。

首先,您需要在脚本顶部添加和

#!/usr/bin/perl
use strict;
use warnings;
这将提醒您许多语法错误,并迫使您完全重新思考/重构代码。不过这是件好事

一件显而易见的事情是,
$a
$b
从来没有初始化过。如果
输入之前的
缺少美元符号,则输入第一个

我会将变量的捕获更改为以下内容:

print "enter a symbol operation symbol to and two numbers to make a calculation";

chomp(my $input = <>);

my ($operation, $x, $y) = split ' ', $input.
print“输入一个符号操作符号和两个数字进行计算”;
chomp(我的$input=);
我的($operation,$x,$y)=拆分“”,$input。

我也不再使用
$a
$b
作为变量名,因为它们是perl排序使用的特殊变量。一旦您确定输入正确,然后开始处理其余的逻辑。

首先,您需要在脚本顶部添加和

#!/usr/bin/perl
use strict;
use warnings;
这将提醒您许多语法错误,并迫使您完全重新思考/重构代码。不过这是件好事

一件显而易见的事情是,
$a
$b
从来没有初始化过。如果
输入之前的
缺少美元符号,则输入第一个

我会将变量的捕获更改为以下内容:

print "enter a symbol operation symbol to and two numbers to make a calculation";

chomp(my $input = <>);

my ($operation, $x, $y) = split ' ', $input.
print“输入一个符号操作符号和两个数字进行计算”;
chomp(我的$input=);
我的($operation,$x,$y)=拆分“”,$input。

我也不再使用
$a
$b
作为变量名,因为它们是perl排序使用的特殊变量。一旦您确定输入正确,然后开始处理其余的逻辑。

首先,您需要在脚本顶部添加和

#!/usr/bin/perl
use strict;
use warnings;
这将提醒您许多语法错误,并迫使您完全重新思考/重构代码。不过这是件好事

一件显而易见的事情是,
$a
$b
从来没有初始化过。如果
输入之前的
缺少美元符号,则输入第一个

我会将变量的捕获更改为以下内容:

print "enter a symbol operation symbol to and two numbers to make a calculation";

chomp(my $input = <>);

my ($operation, $x, $y) = split ' ', $input.
print“输入一个符号操作符号和两个数字进行计算”;
chomp(我的$input=);
我的($operation,$x,$y)=拆分“”,$input。

我也不再使用
$a
$b
作为变量名,因为它们是perl排序使用的特殊变量。一旦您确定输入正确,然后开始处理其余的逻辑。

首先,您需要在脚本顶部添加和

#!/usr/bin/perl
use strict;
use warnings;
这将提醒您许多语法错误,并迫使您完全重新思考/重构代码。不过这是件好事

一件显而易见的事情是,
$a
$b
从来没有初始化过。如果
输入之前的
缺少美元符号,则输入第一个

我会将变量的捕获更改为以下内容:

print "enter a symbol operation symbol to and two numbers to make a calculation";

chomp(my $input = <>);

my ($operation, $x, $y) = split ' ', $input.
print“输入一个符号操作符号和两个数字进行计算”;
chomp(我的$input=);
我的($operation,$x,$y)=拆分“”,$input。

我也不再使用
$a
$b
作为变量名,因为它们是perl排序使用的特殊变量。一旦你确定你的输入正确,然后开始处理你的其余逻辑。

哪里分配了$a和$b?或者我应该把它作为一个答案吗?你能把它作为一个带有密码的答案吗please@JohnYost好的,我怎么才能把它放在一行上呢?你把自己和缩进搞混了。幸运的是大括号匹配并编译。我已经整理好您的代码,使其清晰易读-请看一看。哪里分配了$a和$b?或者我应该把它作为一个答案吗?你能把它作为一个带有密码的答案吗please@JohnYost好的,我怎么才能把它放在一行上呢?你把自己和缩进搞混了。幸运的是大括号匹配并编译。我已经整理好您的代码,使其清晰易读-请看一看。哪里分配了$a和$b?或者我应该把它作为一个答案吗?你能把它作为一个带有密码的答案吗please@JohnYost好的,我怎么才能把它放在一行上呢?你把自己和缩进搞混了。幸运的是,比尔