perl - 阅读文本的好方法是什么?

标签 perl stdin readline

在我的短信脚本中,我读入了要使用此子例程发送的文本:

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/

相关文章:

php - 比较 PERL md5() 和 PHP md5()

perl - 计算grep忽略的行

node.js - 在关闭事件时从 Node.js readline 模块返回数组

linux - BASH - 我如何从整个目录中搜索一个值并找到一些匹配的值,然后通过保存它来即时替换该行

perl - 如何使用 ssh 在远程主机中创建文件以及创建目录

c - 逐行读取文本文件中的字符串并将其存储在链表中

git - 防止 PowerShell "boxing"程序输出

Python:从标准输入读取gzip

c - 如何在 C 中返回 ReadLine() 函数?

具有交互式 child_process 产卵的 Node.js readline