在我的短信脚本中,我读入了要使用此子例程发送的文本:
my $input = input( "Enter the input: " );
sub input {
my $arg = shift;
print $arg if $arg;
print "\n ";
chomp( my $in = <> );
return $in;
}
这样,我只能通过取消所有错误来纠正错误,直到出现错误,并且这只在最后一行。 有更好的方式阅读我的文本吗?
最佳答案
这是读取输入的“正常”方式:
use strict;
use warnings;
# ...
while (my $input = <>)
{
chomp $input;
handle_error($input), next unless validate($input);
# do something else with $input...
}
关于perl - 阅读文本的好方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2392747/