如何在 Perl 中使用 STDIN? [英] How can I slurp STDIN in Perl?
本文介绍了如何在 Perl 中使用 STDIN?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对几个脚本的输出进行了管道传输.其中一个脚本输出一个完整的 HTML 页面,该页面由我的 perl 脚本处理.我希望能够将整个 58K 文本提取到 perl 脚本中(当然,它将包含换行符).
I piping the output of several scripts. One of these scripts outputs an entire HTML page that gets processed by my perl script. I want to be able to pull the whole 58K of text into the perl script (which will contain newlines, of course).
我认为这可能有效:
open(my $TTY, '<', '/dev/tty');
my $html_string= do { local( @ARGV, $/ ) = $TTY ; <> } ;
但它只是没有做我需要的.有什么建议吗?
But it just isn't doing what I need. Any suggestions?
推荐答案
my @lines = <STDIN>;
或
my $str = do { local $/; <STDIN> };
这篇关于如何在 Perl 中使用 STDIN?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文