develooper Front page | perl.perl6.users | Postings from May 2020

Different return values with "say" vs "put" (Nil representation... )

Thread Next
William Michels via perl6-users
May 18, 2020 06:59
Different return values with "say" vs "put" (Nil representation... )
Message ID:

I'm interested in knowing the differences between the return values
when "say" is used compared to "put". My understanding is that "put"
returns Raku's internal representation of a value held by a variable,
while "say" is merely "put" with the .gist method called on it (a
"human readable", often-abbreviated return value).

Below I do "S///" (non-destructive) and "s///" (destructive) text
replacement on a three line text file in bash line [1]. In bash line
[2], the full substituted text file is correctly returned; in bash
line [3] using "say" only the $/ match string is returned. So far so
good. However, a virtually-identical call in bash line [4] using "put"
instead of "say" returns an error for the first line of the target
text file: "Use of Nil in string context in block  at -e line 1".

[1] homedir$ cat demo1.txt
this is a test,
I love Unix,
I like Linux too,

[2] homedir$ perl6 -ne 'say S/love|like/admire/;' demo1.txt
this is a test,
I admire Unix,
I admire Linux too,

[3] homedir$ perl6 -ne 'say s/love|like/admire/;' demo1.txt

[4] homedir$ perl6 -ne 'put s/love|like/admire/;' demo1.txt
Use of Nil in string context
  in block  at -e line 1


[5] homedir$

I'm really trying to understand this error message:  doesn't Raku know
that this is a text replacement operation? How can a 'Nil' be
correctly represented when called by "say", but throw an error when
called by "put"? If the value is absent at the Raku representational
level and throws an error, wouldn't it be reasonable to assume that
the same case would hold for "say"? And finally, does this "say / put"
difference mean that some textual information will be lost from return
values (because "say" will have to be used instead of "put" to avoid

Any enlightenment appreciated,

TIA, Bill.

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About