Re: What are values with : called?

2025-11-02 Thread ToddAndMargo via perl6-users

On 11/2/25 7:13 PM, Bruce Gray wrote:




On Nov 2, 2025, at 20:31, ToddAndMargo via perl6-users  
wrote:

On 11/2/25 4:55 PM, Joseph Brenner wrote:

my $proc = run 'echo', 'Raku is Great!', :out, :err;
$proc.out.slurp(:close).say; # OUTPUT: «Raku is Great!␤»
$proc.err.slurp(:close).say; # OUTPUT: «␤»


Hi Joseph,

The default of both :out and :err is "-",
which is STDOUT and STDERR.  This is
similar to curl's "--output -" which send
to the STDOUT.

What I find puzzling is where else would they
be going?


They (STDOUT and STDERR) would be going to the standard filehandles of the 
*parent* process, just like if you run a command inside a Bash script.
The parent in this case is Raku itself, so they would go to your screen, or 
wherever you have redirect all the Raku STDOUT and/or STDERR to.

% raku -e '
 say "raku talks to STDOUT";
 run(|);
 note "raku talks to STDERR";
 run(|);
 ' > a.txt 2>b.txt

% cat a.txt
 raku talks to STDOUT
 .

% cat b.txt
 raku talks to STDERR
 ls: fake: No such file or directory
 The spawned command 'ls' exited unsuccessfully (exit code: 1, signal: 0)
   in block  at -e line 5




Can I modify :out to :out("eraseme.txt") and
have the output go to a file (eraseme.txt)
instead of STDOUT?  That would be kind of cool.

Yours in puzzlement,
-T


`:out` can take a argument, but it needs a filehandle, not a filename.
It you want to open it in-line, it must be a *writable* filehandle, so this 
will not work:
:out("eraseme.txt".IO)
Instead, use this:
:out("eraseme.txt".IO.open(:w))
or, open the filehandle separately, potentially to use it across several `run` 
commands, then close it manually.




Hi Bruce,

I am slowly catching on.

:out and :err set to "-" are "capturing" the STDOUT and
STDERR to $p.out and $p.err.  Otherwise they go to your
console/shell.

And if you want to alter then, your need to provide
and file handle.

Thank you!
-T




Re: What are values with : called?

2025-11-02 Thread Bruce Gray



> On Nov 2, 2025, at 20:31, ToddAndMargo via perl6-users  
> wrote:
> 
> On 11/2/25 4:55 PM, Joseph Brenner wrote:
>>my $proc = run 'echo', 'Raku is Great!', :out, :err;
>>$proc.out.slurp(:close).say; # OUTPUT: «Raku is Great!␤»
>>$proc.err.slurp(:close).say; # OUTPUT: «␤»
> 
> Hi Joseph,
> 
> The default of both :out and :err is "-",
> which is STDOUT and STDERR.  This is
> similar to curl's "--output -" which send
> to the STDOUT.
> 
> What I find puzzling is where else would they
> be going?

They (STDOUT and STDERR) would be going to the standard filehandles of the 
*parent* process, just like if you run a command inside a Bash script.
The parent in this case is Raku itself, so they would go to your screen, or 
wherever you have redirect all the Raku STDOUT and/or STDERR to.

% raku -e '
say "raku talks to STDOUT";
run(|);
note "raku talks to STDERR";
run(|);
' > a.txt 2>b.txt

% cat a.txt
raku talks to STDOUT
.

% cat b.txt
raku talks to STDERR
ls: fake: No such file or directory
The spawned command 'ls' exited unsuccessfully (exit code: 1, signal: 0)
  in block  at -e line 5



> Can I modify :out to :out("eraseme.txt") and
> have the output go to a file (eraseme.txt)
> instead of STDOUT?  That would be kind of cool.
> 
> Yours in puzzlement,
> -T

`:out` can take a argument, but it needs a filehandle, not a filename.
It you want to open it in-line, it must be a *writable* filehandle, so this 
will not work:
:out("eraseme.txt".IO)
Instead, use this:
:out("eraseme.txt".IO.open(:w))
or, open the filehandle separately, potentially to use it across several `run` 
commands, then close it manually.

-- 
Hope this helps,
Bruce Gray (Util of PerlMonks)



Re: What are values with : called?

2025-11-02 Thread ToddAndMargo via perl6-users

On 11/2/25 4:55 PM, Joseph Brenner wrote:

my $proc = run 'echo', 'Raku is Great!', :out, :err;
$proc.out.slurp(:close).say; # OUTPUT: «Raku is Great!␤»
$proc.err.slurp(:close).say; # OUTPUT: «␤»


Hi Joseph,

The default of both :out and :err is "-",
which is STDOUT and STDERR.  This is
similar to curl's "--output -" which send
to the STDOUT.

What I find puzzling is where else would they
be going?

Can I modify :out to :out("eraseme.txt") and
have the output go to a file (eraseme.txt)
instead of STDOUT?  That would be kind of cool.

Yours in puzzlement,
-T


Re: What are values with : called?

2025-11-02 Thread ToddAndMargo via perl6-users

On 11/2/25 4:55 PM, Joseph Brenner wrote:

ToddAndMargo wrote:


my Proc $p = run( |@args, :err, :out );

What are the values with the ":" in front of them
officially called? I take it "thingies with the
colon in front of them" does not cut it.


They're colon-pairs, though you'll also see them called "adverbs" depending on 
context.
You could call them adverbs here-- they're flags that turn on different 
behavior for the output.

   https://docs.raku.org/routine/run

 If you want to capture standard output or error instead of having
 it printed directly you can use the :out or :err arguments, which
 will make them available using their respective methods: Proc.out
 and Proc.err.


my $proc = run 'echo', 'Raku is Great!', :out, :err;
$proc.out.slurp(:close).say; # OUTPUT: «Raku is Great!␤»
$proc.err.slurp(:close).say; # OUTPUT: «␤»


You could see a construct like that used with an argument though, in
which case it's an "adverbial pair":

   https://docs.raku.org/syntax/Adverbial%20Pair


Adverbs get used a lot with regular expressions, where the syntax is different:

   https://docs.raku.org/syntax/Regex%20adverbs


Thank you!


Re: What are values with : called?

2025-11-02 Thread Joseph Brenner via perl6-users
ToddAndMargo wrote:

> my Proc $p = run( |@args, :err, :out );
> 
> What are the values with the ":" in front of them
> officially called? I take it "thingies with the
> colon in front of them" does not cut it.

They're colon-pairs, though you'll also see them called "adverbs" depending on 
context.
You could call them adverbs here-- they're flags that turn on different 
behavior for the output.

  https://docs.raku.org/routine/run

If you want to capture standard output or error instead of having
it printed directly you can use the :out or :err arguments, which
will make them available using their respective methods: Proc.out
and Proc.err.


   my $proc = run 'echo', 'Raku is Great!', :out, :err;
   $proc.out.slurp(:close).say; # OUTPUT: «Raku is Great!␤»
   $proc.err.slurp(:close).say; # OUTPUT: «␤»


You could see a construct like that used with an argument though, in
which case it's an "adverbial pair":

  https://docs.raku.org/syntax/Adverbial%20Pair


Adverbs get used a lot with regular expressions, where the syntax is different:

  https://docs.raku.org/syntax/Regex%20adverbs






Re: What are values with : called?

2025-11-02 Thread ToddAndMargo via perl6-users

On 11/2/25 3:31 PM, ToddAndMargo via perl6-users wrote:

Hi All,

In the following:

     my Proc $p = run( |@args, :err, :out );

What are the values with the ":" in front of them
officially called?   I take it "thingies with the
colon in front of them" does not cut it.

Many thanks,
-T



search.brave.com's AI to the rescue.  Is this correct?
Sounds to me somewhat like a hash.


https://search.brave.com/search?q=raku+what+values+with+a+colon+in+front+of+them+called%3F&spellcheck=0&source=alteredQuery&summary=1&conversation=e2eb9c9060b8b4e26cf857

In Raku, values with a colon in front of them are known as
colon-pairs. These are used to create Pair objects and are
often employed as named arguments in function calls.
The colon-pair syntax can take various forms, such as
:identifier which creates a Pair with the key being the
identifier and the value being Bool::True, or :!identifier
which creates a Pair with the value being Bool::False. T
hey can also be used with a value, like :key(value), which
is equivalent to key => value