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?
To get it into a single string you want:
I've always used a bare block.
tl;dr: see at the bottom of the post. Explanation first.
practical example
I’ve just wondered about the same, but I wanted something suitable for a shell one-liner. Turns out this is (Korn shell, whole example, dissected below):
Dissecting:
print -nr -- "$x"
echos the whole of$x
without any trailing newline (-n
) or backslash escape (-r
), POSIX equivalent:printf '%s' "$x"
-C7
sets stdin, stdout, and stderr into UTF-8 mode (you may or may not need it)-0777
sets$/
so that Perl will slurp the entire file; reference: manperlrun(1)
-Mutf8 -MEncode
loads two modulesprint encode('MIME-Q', 'Subject: ' . <>);
, let’s look at it from inner to outer, right to left:<>
takes the entire stdin content"Subject: "
Encode::encode
asking it to convert that to MIME Quoted-Printable; print
, again in Korn shell, which is the same as; echo
in POSIX shell – just echoïng a newline.tl;dr
Call
perl
with the-0777
option. Then, inside the script,<>
will contain the entire stdin.complete self-contained example
or
I can't let this opportunity to say how much I love
IO::All
pass without saying:♥ ♥ __ "I really like
IO::All
... a lot" __ ♥ ♥Variation on the POD SYNOPSIS:
Warning:
IO::All
may begin replacing everything else you know about IO in perl with its own insidious goodness.