Hello All,

I've been reviewing literature that discusses using raku/perl6 as a
replacement for common unix utilities. One important unix utility is
"cat". I looked at docs/blogs and found a recommendation to use "$*IN"
along with "slurp" (references at bottom). Using a seven-line test
file "testthis_abc_def.txt" below (1), the recommended "slurp" code
works as expected (2).

However, another recommendation to use "$*IN" along with the "get"
method fails when a blank line is encountered, only returning
truncated output (3). I tried correcting truncated output seen with
"get" by playing with the command-line arguments "-ne" (4) and "-pe"
(5), but only ended up mangling output even further.

Can "get" be used in when writing raku/perl6 replacement code for "cat"?

Any advice appreciated,

Bill.


[1]mydir$ cat testthis_abc_def.txt
a
b
c

d
e
f
[2]mydir$ perl6 -e 'say $*IN.slurp;' < testthis_abc_def.txt
a
b
c

d
e
f

[3]mydir$ perl6 -e '.say while $_ = $*IN.get;' < testthis_abc_def.txt
a
b
c
[4]mydir$ perl6 -ne '.say while $_ = $*IN.get;' < testthis_abc_def.txt
b
c
e
f
[5]mydir$ perl6 -pe '.say while $_ = $*IN.get;' < testthis_abc_def.txt
b
c

e
f
(Mu)
[6]mydir$


REFERENCES:
1. https://docs.raku.org/routine/slurp
2. https://docs.raku.org/routine/get
3. https://andrewshitov.com/2019/09/09/the-cat-utility-written-in-perl-6/
4. 
https://stackoverflow.com/questions/52597984/catching-exception-of-a-shell-command-in-perl-6

Reply via email to