develooper Front page | perl.perl6.users | Postings from September 2017

Re: Need append help

Thread Previous | Thread Next
September 29, 2017 19:58
Re: Need append help
Message ID:
On 09/29/2017 12:41 PM, Brandon Allbery wrote:
> On Fri, Sep 29, 2017 at 3:27 PM, ToddAndMargo < 
> <>> wrote:
>     I do not understand.  :'(
> There's not enough syntax to go around, so perl 6 has to use spaces 
> sometimes to figure out what you want.
>     $ perl6 -e 'my $x="abc"; $x[R~]= "yyz"; say $x;'
>     ===SORRY!=== Error while compiling -e
>     Missing required term after infix
> I explained this one earlier. Things would go faster if you read entire 
> messages.
> The sequece `$x[` could potentially mean that $x is an array stored in a 
> scalar variable, and you are asking for a particular item from the 
> array. Or it could mean the start of a complex operator to be applied to 
> $x. You need a space to tell it which you intend: without the space it 
> sees the indexing operation, without it sees the complex operator.

Ding!   It finally sunk in.  "$x[" is an index, where "$x [" means an
operation.  Took a bit, but I finally got there.

> In this case, the complex operator is composed of a basic operator '~' 
> (string concatenation), modified twice: once with the reversing 
> metaoperator (Rop), and a second time with the in-place assigment 
> operator (postfix =). Just as you need to use parentheses in `2 + 3 * 5` 
> if you want it to be (2 + 3) * 5 instead of 2 + (3 * 5), you need braces 
> to tell it how to combine these special operators --- and you must *not* 
> have a space before the postfix =. Which is why you got this error:
>     $ perl6 -e 'my $x="abc"; $x [R~] = "yyz"; say $x;'
>     ===SORRY!=== Error while compiling -e
>     Preceding context expects a term, but found infix = instead
> With the space before it, it is no longer a modifier for the reversed 
> concatenation [R~] but a standalone assignment operator, which can't 
> happen there because it already has an operator [R~] so now it needs to 
> see a term (expression, roughly).

Hi Brandon,

Some of my issues comes from Modula2 where stings and arrays of 
characters.  And perl 5 with is "~=" or "=~".  I forget.

Thank you for your patience!


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About