See https://docs.perl6.org/language/quoting for more information.
Really you only need to remember that ' ' is very bare-bones, while " " has more features. --- Single quotes only allow \\, \qq[...] and escaping the delimiter with \ (All other backslashes are left as they are in the text.) While double quotes also enable :s, :a, :h, :f, :c, :b modes "\t" =:= Q :s :a :h :f :c :b [\t] :s / :scalar --- interpolate $ vars :a / :array --- interpolate @ vars :h / :hash --- interpolate % vars :f / :function --- interpolate & calls :c / :closure --- interpolate {} closures :b / :backslash --- enable backslash escapes (\n, \qq, \$foo, etc) (:b / :backslash is a superset of :q / :single) Note that 'foo' is really short for all of these: Q :q [foo] Q :single [foo] q [foo] (The two characters [ ] can be just about any non-alphanumeric characters.) and "foo\n" is short for these Q :qq [foo\n] Q :double [foo\n] Q :s :a :h :f :c :b [foo\n] Q :scalar :array :hash :function :closure :backslash [foo\n] q :s :a :h :f :c :b [foo\n] q :scalar :array :hash :function :closure :backslash [foo\n] qq [foo\n] This can be useful for say embedding a scalar variable, while @ is litteral. Q :scalar [$usern...@example.com] You can even turn off features qq :!array [$usern...@example.com] There is also 「 」 (and Q) which has no features. (You can't even escape the delimiter.) 'abc\\' =:= 「abc\」 =:= Q [abc\] --- P.S. Note that I added spaces for clarity, in most cases they aren't actually needed. Q:scalar:array:hash:function:closure:backslash[foo\n] Also :q follows all of the rules of adverbs, except that in this case they have to be compile-time values qq :array(False) [$usern...@example.com] On Wed, Jul 31, 2019 at 7:30 PM William Michels via perl6-users < perl6-us...@perl.org> wrote: > Great explanation, Andy. Thank you! Actually it's pretty exciting that > split now works as a method in perl6, including splitting on a regex > as in ".split(/\:+/)" ...see first line below (REPL example): > > > say $_ = > "apple:banana:carrot:dragonfruit::favabean".split(/\:+/).join("\t"); > apple banana carrot dragonfruit favabean > > say $_ = .split("\t").join("_"); > apple_banana_carrot_dragonfruit_favabean > > say $_ = .split("_").join(";"); > apple;banana;carrot;dragonfruit;favabean > > say $_ = .split(";")[0,2,1,4].join("|"); > apple|carrot|banana|favabean > > say $_.perl > "apple|carrot|banana|favabean" > > put $_ > apple|carrot|banana|favabean > > > > Still trying to figure out why split will take single-quoted literals > like ':' but join appears to require a double-quoted $separator as in > "\t" or "\n" (example below). In the last line, it seems that escaped > characters must be double-quoted, while non-escaped separators can be > single-quoted. At least that's what I'm concluding... . --Best, Bill. > > > say $_ = "apple|carrot|banana|favabean" > apple|carrot|banana|favabean > > say .split(/\|+/).join('\n'); > apple\ncarrot\nbanana\nfavabean > > say .split(/\|+/).join("\n"); > apple > carrot > banana > favabean > > say $_ = > "apple:banana:carrot:dragonfruit::favabean".split(/\:+/)[0,2,1,4].join('____'); > apple____carrot____banana____favabean > > > > > > > On Wed, Jul 31, 2019 at 3:28 PM Andy Bach <andy_b...@wiwb.uscourts.gov> > wrote: > > > > > , but I had to change .split(':') either to .split(":") or > > > > because your -e ' .... ' quotes are the same, so bash breaks it up into > 3 chunks > > say .split( > > : > > )[0, 2, 1, 5].join("\t") for > > > > and perl just gets the first as the "program" > > > > ________________________________ > > From: William Michels via perl6-users <perl6-us...@perl.org> > > Sent: Wednesday, July 31, 2019 4:28 PM > > To: Patrick R. Michaud <pmich...@pobox.com> > > Cc: perl6-users <perl6-us...@perl.org> > > Subject: Re: while(<>){...} analog? > > > > Hi Patrick, I used both your examples as perl6 one-liners. I'm not > > sure why, but I had to change .split(':') either to .split(":") or > > .split(/\:/) for both example to work. Maybe it's a command-line > > thing? Possibly because I'm on a Mac? Also, to get the second example > > to work I change the 'for lines' preamble to 'for lines()' then it's > > fine (otherwise perl6 balks with an awesome error: "Function 'lines' > > needs parens to avoid gobbling block"). > > > > Thanks again for all your help! --Best, Bill. > > > > # test file: six_fruits1.txt > > mbook:~ homedir$ cat six_fruits1.txt > > apple:banana:carrot:dragonfruit:eggplant:favabean > > apricot:basil:cabbage:dill:escarole:fennel > > acai:beets:celery:daikon:endive:figs > > > > # First example: > > mbook:~ homedir$ perl6 -e 'say .split(":")[0, 2, 1, 5].join("\t") for > > lines' six_fruits1.txt > > apple carrot banana favabean > > apricot cabbage basil fennel > > acai celery beets figs > > mbook:~ homedir$ perl6 -e 'say .split(/\:/)[0, 2, 1, 5].join("\t") for > > lines' six_fruits1.txt > > apple carrot banana favabean > > apricot cabbage basil fennel > > acai celery beets figs > > > > # Second example: note changed 'for lines' to 'for lines()' > > mbook:~ homedir$ perl6 -e ' for lines() { say .split(":")[0, 2, 1, > > 5].join("\t") }' six_fruits1.txt > > apple carrot banana favabean > > apricot cabbage basil fennel > > acai celery beets figs > > mbook:~ homedir$ perl6 -e ' for lines() { say .split(/\:/)[0, 2, 1, > > 5].join("\t") }' six_fruits1.txt > > apple carrot banana favabean > > apricot cabbage basil fennel > > acai celery beets figs > > > > > > On Mon, Jul 29, 2019 at 12:56 PM Patrick R. Michaud <pmich...@pobox.com> > wrote: > > > > > > My guesses at Perl 6 versions of the Perl 5 example: > > > > > > say .split(':')[0, 2, 1, 5].join("\t") for lines; > > > > > > -or- > > > > > > for lines { say .split(':')[0, 2, 1, 5].join("\t") } > > > > > > Pm > > > > > > > > > On Mon, Jul 29, 2019 at 12:49:51PM -0700, William Michels via > perl6-users wrote: > > > > Hello, Just a short backgrounder to say that this question arose this > > > > past weekend at a Perl6 Meetup (Oakland, CA). Specifically we were > > > > looking at how to write a Perl6 version of some introductory Perl5 > > > > code in "Learning Perl", 7th Edition by Tom Phoenix, brian d foy, > > > > Randal L. Schwartz: > > > > > > > > #Perl 5 code below: > > > > while (<>) { > > > > chomp; > > > > print join("\t", (split /:/)[0, 2, 1, 5] ), "\n"; > > > > } > > > > > > > > > https://www.oreilly.com/library/view/learning-perl-7th/9781491954317/ch01.html > > > > > > > > (Thanks to Joseph Brenner for organizing the Perl6 Meetup). > > > > > > > > > > > > > > > > > > > > > > > > > > > > On Mon, Jul 29, 2019 at 2:09 AM Elizabeth Mattijsen <l...@dijkmat.nl> > wrote: > > > > > > > > > > Also, you can make this conditional: show me all the comment > lines of a source file: > > > > > > > > > > > > > > > $ perl6 -e '.say if .starts-with('#') for lines' source-file > > > > > > > > > > > > > > > > On 29 Jul 2019, at 10:06, Richard Hainsworth < > rnhainswo...@gmail.com> wrote: > > > > > > > > > > > > Also no need for all the brackets > > > > > > > > > > > > .say for lines; > > > > > > > > > > > > This is quite idiomatic Perl 6 and not golfing > > > > > > > > > > > > On Mon, 29 Jul 2019, 07:13 Joseph Brenner, <doom...@gmail.com> > wrote: > > > > > > > Hmmm. I would expect that to be in the Perl 5 to Perl 6 > Migration Guides, but I do not see it there. > > > > > > > > > > > > Exactly, I was just looking there, and I ended up playing around > with > > > > > > the method form of lines, and didn't think to try the function > > > > > > form of it. > > > > > > > > > > > > To summarize, if the goal is to write a "simple_echo" script that > > > > > > can work with a file name or with lines on standard input: > > > > > > > > > > > > simple_echo lines.txt > > > > > > cat lines.txt | simple_echo > > > > > > > > > > > > The perl5 version would probably be: > > > > > > > > > > > > #!/usr/bin/env perl > > > > > > while(<>){ > > > > > > print; > > > > > > } > > > > > > > > > > > > The perl6 version would be something like: > > > > > > > > > > > > #!/usr/bin/env perl6 > > > > > > use v6; > > > > > > for lines() { > > > > > > say $_; > > > > > > } > > > > > > > > > > > > > > > > > > The kind of thing I was playing with was: > > > > > > > > > > > > #!/usr/bin/env perl6 > > > > > > use v6; > > > > > > my @lines = $*ARGFILES.IO.lines; > > > > > > say @lines; > > > > > > > > > > > > That works for lines from a file, but not from standard input, > and the > > > > > > error message isn't tremendously helpful: > > > > > > > > > > > > No such method 'lines' for invocant of type 'IO::Special' > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > On 7/28/19, Bruce Gray <robertbrucegr...@gmail.com> wrote: > > > > > > > > > > > > > > > > > > > > >> On Jul 28, 2019, at 6:20 PM, Joseph Brenner < > doom...@gmail.com> wrote: > > > > > > >> > > > > > > >> I was just wondering if there's some direct analog in perl6 > to the > > > > > > >> perl5 construct: > > > > > > >> > > > > > > >> while(<>){ ... } > > > > > > >> > > > > > > >> If I'm planning on passing a filename on the command-line, I > can just > > > > > > >> get it out of $*ARGFILES easily enough, but what if I also > wanted it > > > > > > >> to work on lines passed in via standard input? > > > > > > > > > > > > > > > > > > > > > `lines` , as a sub instead of a method, and no arguments. > > > > > > > > > > > > > > See: https://docs.perl6.org/routine/lines#(Cool)_routine_lines > > > > > > > Without any arguments, sub lines operates on $*ARGFILES, > which defaults to > > > > > > > $*IN in the absence of any filenames. > > > > > > > > > > > > > > For example: > > > > > > > perl6 -e 'say .join("\t") for lines().rotor(4);' > path/to/file.txt > > > > > > > > > > > > > > Hmmm. I would expect that to be in the Perl 5 to Perl 6 > Migration Guides, > > > > > > > but I do not see it there. > > > > > > > > > > > > > > — > > > > > > > Hope this helps, > > > > > > > Bruce Gray (Util of PerlMonks) > > > > > > > > > > > > > > >