<a b c>
is the same as
Q :single :words < a b c >
Note that :single means it acts like single quotes.
Single quotes don't do anything to convert '\n' into anything other than a
literal '\n'.
If you want that to be converted to a linefeed you need to use double quote
semantics (or at least turn on :backslash).
Q :double :words < a\n b\n c >
Of course that also doesn't do what you want because a linefeed character
is also whitespace, so it gets removed along with the rest of the
whitespace.
What you want to do use is :quotewords and "".
Q :quotewords < "a\n" "b\n" c >
The short way to write that is
<< "a\n" "b\n" c >>
Although if you are going to append a newline to every element I would
consider writing it this way:
< a b c > X~ "\n"
or
< a b c > »~» "\n"
On Sat, Nov 14, 2020 at 1:21 PM ToddAndMargo via perl6-users <
[email protected]> wrote:
> >> On Nov 14, 2020, at 14:12, ToddAndMargo via perl6-users
> <[email protected]> wrote:
> >>
> >> On 2020-11-14 11:08, Curt Tilmes wrote:
> >>> On Sat, Nov 14, 2020 at 2:03 PM ToddAndMargo via perl6-users
> >>> <[email protected]> wrote:
> >>>> Just out of curiosity, why is the \n printed out literally here?
> >>>> p6 'my @x = <"aaa\n","bbb\n","ccc\n">; for @x {print @_};'
> >>> Your 'word quoting' <> is sort of like single quotes -- it keeps the
> >>> literal stuff. You could
> >>> use <<>> which is more like double quotes,
> >>> Curt
> >>
> >> or remove the commas. I put everything in [0]
> >>
> >>
> >> $ p6 'my @x = <aaa\n bbb\n ccc\n>; for @x {print "$_\n";}'
> >> aaa\n
> >> bbb\n
> >> ccc\n
> >>
> >> $ p6 'my @x = <<aaa\n bbb\n ccc\n>>; for @x {print "$_\n";}'
> >> aaa
> >> bbb
> >> ccc
> >>
> >> $ p6 'my @x = <<aaa\n bbb\n ccc\n>>; for @x {print "$_";}'
> >> aaabbbccc
> >>
> >> What am I missing?
> >>
> >> -T
>
>
> On 2020-11-14 11:18, Matthew Stuckwisch wrote:
> > The <…> and «…» constructors break on whitespace.
> >
> > So <a,b,c,d,e,f> will actually produce the following array:
> >
> > ["a,b,c,d,e,f"]
> >
> > It's only one item. If we placed space after the comma, that is, <a, b,
> c, d, e, f>, you'd get a six item list, but with the commas attached to all
> but the final:
> >
> > ["a,", "b,", "c,", "d,", "e,", "f"]
> >
> > By replacing the commas with spaces, e.g., <a b c d e f>, you allow it
> to break into ["a", "b", "c", "d", "e", "f"]
> >
> > Matéu
> >
>
> Ya, I caught that booboo. :'(
>
> Question still stands. Why is the \n working as a CR/LF and
> being printed as a litteral?
>