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

Reply via email to