perl

How can I slurp STDIN in 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?


Solution

  • my @lines = <STDIN>;
    

    or

    my $str = do { local $/; <STDIN> };