Re: How do I read a pipe into a one liner?
On 10/29/2017 11:18 PM, ToddAndMargo wrote: 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: Follow up: With the help of the guys on the chat line, here is the keeper file I wrote myself: -T How to read a "pipe": .lines gives you an array of lines, each with the trailing newline removed All three of the follow output the data without the formatting: $ ls *Test.pl6* | perl6 -e 'say "$*IN.lines;' $ ls *Test.pl6* | perl6 -e 'my $x=lines(); say "$x";' $ ls *Test.pl6* | perl6 -e 'my $x=get(); say "$x";' CallFrameTest.pl6 CommandLineTest.pl6 CurlUtilsTest.pl6 FileTest.pl6 HashIndexTest.pl6 InlineTest.pl6 LogTest.pl6 LogTest.pl6.log MonthTest.pl6 RunNoShellTest.pl6 ShArTest.pl6 SubTest.pl6 TermTest.pl6 Timo.Attachmnet.Test.pl6 X11Clipboard.Test.pl6 X11Test.pl6 Xlib.Test.pl6 "get" reads one line at a time into a string (the whole thing into an array) $ ls *Test.pl6* | perl6 -e 'say get(); say get(); say get();' CallFrameTest.pl6 CommandLineTest.pl6 CurlUtilsTest.pl6 "slurp" is the only one that keeps the entire original bash command's formatting into a string: $ ls *Test.pl6* | perl6 -e 'my $x=slurp(); say "$x";' $ ls *Test.pl6* | perl6 -e 'my @x=$*IN.lines; for @x { say $_ };' CallFrameTest.pl6 CommandLineTest.pl6 ... X11Test.pl6 Xlib.Test.pl6 $ ls *Test.pl6* | perl6 -e 'my $x=$*IN.slurp; say "$x";' CallFrameTest.pl6 CommandLineTest.pl6 ... X11Test.pl6 Xlib.Test.pl6
Re: How do I read a pipe into a one liner?
On 10/29/2017 11:18 PM, ToddAndMargo wrote: 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 #!/usr/bin/perl use strict; use warnings; chomp(my $Pipe = ( ! -t \*STDIN ) ? do{local $/; } : q{}); print "This was read from the pipe:\n<$Pipe>\n\n"; print "These are the list of parameters:\n<@ARGV>\n"; __END__ That was not a one liner example. I actually need to know how to do both.
How do I read a pipe into a one liner?
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 #!/usr/bin/perl use strict; use warnings; chomp(my $Pipe = ( ! -t \*STDIN ) ? do{local $/; } : q{}); print "This was read from the pipe:\n<$Pipe>\n\n"; print "These are the list of parameters:\n<@ARGV>\n"; __END__ 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: These are the list of parameters: <1 2 3> $ (sleep 3; echo abc ) | ReadAPipe.pl 1 2 3 This was read from the pipe: These are the list of parameters: <1 2 3> $ echo abc | ReadAPipe.pl This was read from the pipe: 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>