Re: my command line notes:
On 03/15/2017 10:04 AM, Timo Paulssen wrote: On 14/03/17 20:58, ToddAndMargo wrote: #!/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>"; } 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. say '@*ARGS has ' ~ @*ARGS.elems ~ " elements"; say ' @*ARGS = <' ~ @*ARGS ~ ">"; say ' @*ARGS.perl = <' ~ @*ARGS.perl ~ ">\n"; 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 = @*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 ~~
Re: my command line notes:
On 14/03/17 20:58, ToddAndMargo wrote: > > #!/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>"; } > 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. say '@*ARGS has ' ~ @*ARGS.elems ~ " elements"; say ' @*ARGS = <' ~ @*ARGS ~ ">"; say ' @*ARGS.perl = <' ~ @*ARGS.perl ~ ">\n"; 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 = @*things.perl = <["raindrops on roses", "whiskers on kittens", "bright copper kettles"]> Hope that helps! - Timo
Re: my command line notes:
On 03/14/2017 01:37 PM, ToddAndMargo wrote: On 03/14/2017 01:26 PM, Will Coleda wrote: FYI https://docs.perl6.org/language/functions#index-entry-MAIN Thank you! So far, I haven't gotten to creative: my $DebugFlag = @*ARGS.elems; # generate a crash report if > 0
Re: my command line notes:
On 03/14/2017 01:26 PM, Will Coleda wrote: FYI https://docs.perl6.org/language/functions#index-entry-MAIN Thank you!
Re: my command line notes:
FYI https://docs.perl6.org/language/functions#index-entry-MAIN On Tue, Mar 14, 2017 at 3:58 PM, ToddAndMargowrote: > Hi All, > > I wrote myself a little demonstration program on > reading elements from the command line. I thought > it might be useful to others (DuckDuckGo is a bust > on Perl 6 and the command line): > > -T > > > Perl 6: command line parameters: > > > #!/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>"; } > > > > $ ./CommandLineTest.pl6 > command line is empty > > $ ./CommandLineTest.pl6 a b c > @*ARGS has 3 elements >@*ARGS = >@*ARGS.perl = <["a", "b", "c"]> > > say in a loop: >@*ARGS[0] = >@*ARGS[1] = >@*ARGS[2] = > > > -- > ~~ > Computers are like air conditioners. > They malfunction when you open windows > ~~ -- Will "Coke" Coleda