develooper Front page | perl.perl6.users | Postings from October 2017

How do I read a pipe into a one liner?

Thread Next
From:
ToddAndMargo
Date:
October 30, 2017 06:18
Subject:
How do I read a pipe into a one liner?
Message ID:
5a9b0d16-74d9-f814-9777-c706ea918480@zoho.com
Dear List,


I am trying to translate this P5 coder to P6.
I am looking at how to read a pipe into a line liner:

ReadAPipe.pl
<code>
#!/usr/bin/perl

use strict;
use warnings;

chomp(my $Pipe = ( ! -t \*STDIN ) ? do{local $/; <STDIN>} : q{});
print "This was read from the pipe:\n<$Pipe>\n\n";
print "These are the list of parameters:\n<@ARGV>\n";

__END__
</code>



Many thanks,
-T


$ ReadAPipe.pl
This was read from the pipe:
<>

These are the list of parameters:
<>


$ ReadAPipe.pl 1 2 3
This was read from the pipe:
<>


These are the list of parameters:
<1 2 3>


$ echo abc | ReadAPipe.pl 1 2 3
This was read from the pipe:
<abc>

These are the list of parameters:
<1 2 3>


$ (sleep 3; echo abc ) | ReadAPipe.pl 1 2 3
This was read from the pipe:
<abc>

These are the list of parameters:
<1 2 3>


$ echo abc | ReadAPipe.pl
This was read from the pipe:
<abc>

These are the list of parameters:
<>


$ sleep 3 | ReadAPipe.pl 1 2 3
This was read from the pipe:
<>

These are the list of parameters:
<1 2 3>

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About