On 03/15/2017 10:04 AM, Timo Paulssen wrote:
On 14/03/17 20:58, ToddAndMargo wrote:
<code>
#!/usr/bin/perl6

if not @*ARGS.elems > 0 { say "command line is empty"; exit 0; }

say "\@\*ARGS has " ~ @*ARGS.elems ~ " elements";
say "   \@\*ARGS      = <" ~ @*ARGS      ~ ">";
say "   \@\*ARGS.perl = <" ~ @*ARGS.perl ~ ">\n";

say "say in a loop:";
for @*ARGS.kv -> $indx, $Arg { say "   \@\*ARGS[$indx] = <$Arg>"; }
</code>

Please note that if you don't interpolate into a string anyway, you can
use '' instead of "" and you won't have to backslash stuff at all.

<code>
    say '@*ARGS has ' ~ @*ARGS.elems ~ " elements";
    say '   @*ARGS      = <' ~ @*ARGS      ~ ">";
    say '   @*ARGS.perl = <' ~ @*ARGS.perl ~ ">\n";
</code>

But even with "" you don't have to backslash the @ and the * there. You
only would have to do that if you had a method call that includes
parenthesis or if you had a subscript after something that looks just
like an array variable. (these rules depend on the sigil, they are the
same for %-sigiled vars, but $-sigiled vars will interpolate much more
readily.)

    timo@schmand ~> perl6 -e 'my @*things = "raindrops on roses",
"whiskers on kittens", "bright copper kettles";
                    say "@*things has @*things.elems() elements";
                    say "    @*things = <@*things.Str()>";
                    say "    @*things.perl = <@*things.perl()>\n";'
    @*things has 3 elements
        @*things = <raindrops on roses whiskers on kittens bright copper
kettles>
        @*things.perl = <["raindrops on roses", "whiskers on kittens",
"bright copper kettles"]>

Hope that helps!
  - Timo


Hi Timo,

Thank you!  "" '' can be very helpful.  Very sweet example.
(one example worth 1000 words)

I tend to escape things and use regular quotes so I remember
what I have to escape and what I don't.  It is just a memory
crutch.

And I am going to have to look up @* variables, again.

-T


--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Computers are like air conditioners.
They malfunction when you open windows
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Reply via email to