Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I slurp STDIN in Perl?

Tags:

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).

I thought this might work:

open(my $TTY, '<', '/dev/tty');

my $html_string= do { local( @ARGV, $/ ) = $TTY ; <> } ;

But it just isn't doing what I need. Any suggestions?

like image 898
phileas fogg Avatar asked May 25 '12 23:05

phileas fogg


People also ask

What is Stdin Perl?

STDIN in Scalar Context In order to take input from the keyboard or operator is used in Perl. This operator reads a line entered through the keyboard along with the newline character corresponding to the ENTER we press after input.

Which tag is used to take inputs in Perl?

Input to a Perl program can be given by keyboard with the use of <STDIN>. Here, STDIN stands for Standard Input .

What is $_ in Perl?

The most commonly used special variable is $_, which contains the default input and pattern-searching string. For example, in the following lines − #!/usr/bin/perl foreach ('hickory','dickory','doc') { print $_; print "\n"; }


1 Answers

my @lines = <STDIN>;

or

my $str = do { local $/; <STDIN> };
like image 127
Sinan Ünür Avatar answered Oct 30 '22 10:10

Sinan Ünür