perl 怎么判断一个字符是指定字符
就比如#!/usr/bin/perl-wusestrict;my($line,$result);print"Enteranemptylinetoquit.";OUTERL...
就比如
#!/usr/bin/perl -w
use strict;
my($line, $result);
print "Enter an empty line to quit. ";
OUTERLOOP:
while (1) {
print "Enter your expression and type [ENTER] : ";
$line = <STDIN>;
chomp $line;
last if not $line;
INNERLOOP:
foreach (split(//,$line)) {
if (!($_==(0|1..9|'+'|'-'|'*'|'/'))){
print "Input error!";
last OUTERLOOP;
}
}
$result = eval "$line";
print "\tError : $@\n" if $@;
print "\tResult: $result\n" if not $@;
}
1;
内循环里想判断如果输入不是数字、+-*/ 就退出外循环报错 但是这样写貌似跑起来会有错,好像自动把‘+’‘-’之类的算成ASCII码?
比如报错中第一行说Argument "+" isn't numeric in bitwise or (|) at 062eval .pl line 1, <STDIN> line 1.
应该怎么改?求高人指点~~ 展开
#!/usr/bin/perl -w
use strict;
my($line, $result);
print "Enter an empty line to quit. ";
OUTERLOOP:
while (1) {
print "Enter your expression and type [ENTER] : ";
$line = <STDIN>;
chomp $line;
last if not $line;
INNERLOOP:
foreach (split(//,$line)) {
if (!($_==(0|1..9|'+'|'-'|'*'|'/'))){
print "Input error!";
last OUTERLOOP;
}
}
$result = eval "$line";
print "\tError : $@\n" if $@;
print "\tResult: $result\n" if not $@;
}
1;
内循环里想判断如果输入不是数字、+-*/ 就退出外循环报错 但是这样写貌似跑起来会有错,好像自动把‘+’‘-’之类的算成ASCII码?
比如报错中第一行说Argument "+" isn't numeric in bitwise or (|) at 062eval .pl line 1, <STDIN> line 1.
应该怎么改?求高人指点~~ 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询