the equivalent of perl6 is Pair , and its constructor statement => . They are immutable - after creation, the key and value cannot be changed;
$ perl6 > my $destination = "Name" => "Sydney" ; Name => Sydney > say $destination.WHAT ; (Pair) > $destination.value = "London"; Cannot modify an immutable Str in block <unit> at <unknown file> line 1 >
Like the bold comma from perl5, the constructor does not require the left side to be quoted if it has one identifier. There is an alternative syntax for expressing pairs called "colon". You can collect several Pear togeather into a list, but they will only be available to positionaly;
> $destination = ( Name => "Sydney" , :Direction("East") , :Miles(420) ); (Name => Sydney Direction => East Miles => 420) > say $destination.WHAT ; (List) > say $destination[1] ; Direction => East >
There are convenient colon syntax options â if the value is a string, you can replace the brackets with brackets and discard the quotation marks. If the value is an integer, you can list the key immediately after the value without quotes. If the value is logical, you can list only the key, if the value is True or a prefix ! if the value is False.
Finally, you can assign several of them to a hash, where access to these values ââwill be possible using the key and changed;
> my %destination = ( :Name<Sydney> , :Direction<East> , :420miles , :!visited ) ; Direction => East, Name => Sydney, miles => 420, visited => False > say %destination<miles> ; 420 > %destination<visited> = True ; True >
Marty source share