You're using doubles quotes for the string you're passing to Raku.

This means the Shell will do variable interpolation. So it see's "my $map =
Map.new()" and puts the value of it's variable $map in their.

But it doesn't exist. So Raku gets "my = Map.new()" (Note the space where
$map was). And complains. (You can see that in the error).

I'd advise *always* suing single quotes to pass strings into Raku on the
command line. If you need single quotes in your code use q[] instead.

So :

p6 'my $map = Map.new("a", 1, "b", 2); say $map{"a"}; say $map{ "a", "b"
};'

Should work just fine.

%e := Map.new binds %e to the Map if you did %e = Map.new it will treat the
Map as the first element in a list and probably complain.

On the other hand $e = Map.new is assigning to a Scalar so it doesn't
expect to be taking a list of values.

If that makes sense?

On Wed, 4 Dec 2019 at 10:22, ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> Hi All,
>
> I am going through the examples on
>     https://docs.perl6.org/type/Map.html
>
> $ p6 "my $map = Map.new('a', 1, 'b', 2); say $map{'a'}; say $map{ 'a',
> 'b' };"
> ===SORRY!=== Error while compiling -e
> Malformed my
> at -e:1
> ------> my⏏  = Map.new('a', 1, 'b', 2); say {'a'};
>
> What the heck is a 'Malformed my"?  I copied and pasted
> from the second set of examples.
>
> And why is the first example:
>       %e := Map.new
> and the second example
>       $e = Map.new
> ?
>
> Many thanks,
> -T
>


-- 
Simon Proctor
Cognoscite aliquid novum cotidie

http://www.khanate.co.uk/

Reply via email to