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>

Reply via email to