On Sun, Oct 14, 2018 at 10:35 AM ToddAndMargo via perl6-users
<perl6-users@perl.org <mailto:perl6-users@perl.org>> wrote:
On 10/14/18 2:29 AM, Ralph Mellor wrote:
> In P6 "assign" means use of `=`.
>
> And "assign to" means to copy into the thing on the left of the `=`.
>
> And to copy into something the thing has to be a mutable container.
>
> The error message is saying that $ReturnStr is bound to an
> immutable value (eg a string) not a container.
>
> So that's presumably a problem with whatever code you've
> written that has earlier bound $ReturnStr to an immutable value.
>
> --
> raiph
my Str $ReturnStr = "";
I think slurp-rest does not support
enc => 'utf8-c8'
:'(
See my other letter on this thread
On 10/14/18 2:43 AM, Ralph Mellor wrote:
I just tried slurp-rest with a specified encoding and it worked fine.
Are you sure you don't bind $ReturnStr between the
declaration you've shiown and the use you've shown?
--
raiph
If I do, I am not seeing it. Here is the specific code:
sub RunNoShellAll( Str $RunString, Int $StdOut, Int $StdErr, Int $Code ) {
# $RunString Comnad line to run without a shell
# $StdOur read and return the STDOUT 1=yes, 0=no
# $StdErr read and return the STDERR 1=yes, 0=no
# $Code read and return the return code 1=yes, 0=no
# Note: If reading the STDERR, it is PRESUMED you also will be
reading the STDIN.
# If only reading the return code, it is presumed that you
want the STDERR
# and STDIN to be silent.
# place each value into a cell in an array. Keep quoted
# values together
# print "Run String = <$RunString>\n";
# returns
# StdOut as Str $ReturnStr
# StdErr as Str $ReturnErr
# Return Code ($?) as Int $RtnCode
my Buf $BufStdErr;
my Str $ReturnStr = "";
my Str $ReturnErr = "";
my Int $RtnCode = 0;
my $proc;
my @RunArray = $RunString ~~ m:global/ [ '"' <-[ " ]> * '"' | \S+ ] /;
# shells remove the quote, so you have to here as well
for @RunArray.kv -> $index, $value { @RunArray[$index] ~~ s:g/\"//; };
# for @RunArray.kv -> $index, $value { say "\$RunArray[$index] =
<$value>"; }; print "\n";
if $StdErr { $proc = run( @RunArray, :err, :out ); }
elsif $StdOut { $proc = run( @RunArray, :out ); } #
STDERR goes to the terminal
else { $proc = run( @RunArray, :err, :out ); } #
STDIN and STDERR are silent
if $Code { $RtnCode = $proc.status; }
# if $StdErr { $ReturnErr = $$proc.err.slurp-rest( enc =>
'utf8-c8' ); }
# if $StdOut { $ReturnStr = $$proc.out.slurp-rest( enc =>
'utf8-c8' ); }
if $StdErr { $ReturnErr = $$proc.err.slurp-rest; }
if $StdOut { $ReturnStr = $$proc.out.slurp-rest; }
# $ReturnStr = $BufStdErr.decode("utf8-c8") }
return( $ReturnStr, $ReturnErr, $RtnCode );
}