Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Perl 6, defining a hash with interpolated string

by molecules (Monk)
on Aug 04, 2010 at 17:43 UTC ( #852927=note: print w/ replies, xml ) Need Help??


in reply to Perl 6, defining a hash with interpolated string

I'm not really sure, but it seems that the colon is effectively ignored in that context. Try the following:

use v6; my $item = :[:[:[$hkey]]]; say $item.perl; # outputs [[["somekey"]]]


Comment on Re: Perl 6, defining a hash with interpolated string
Download Code
Replies are listed 'Best First'.
Re^2: Perl 6, defining a hash with interpolated string
by Mr_Micawber (Beadle) on Aug 04, 2010 at 19:12 UTC

    I think I was looking for the interpolating analog of this model for specifying a literal hash pair:

    %kv = :LiteralKey<LiteralValue>
      The last two of the following examples give you interpolation, but it is more of the "normal" interpolation you would expect in Perl.
      use v6; my %kv1 = :LiteralKey<LiteralValue>; say :%kv1.perl; my %kv2 = <LiteralKey>,<LiteralValue>; say :%kv2.perl; my $var3 = 'Literal'; my %kv3 = "{$var3}key",'LiteralValue'; say :%kv3.perl; my $var4 = 'LiteralKey'; my %kv4 = "$var4",'LiteralValue'; say :%kv4.perl;
      gives you
      "kv1" => {"LiteralKey" => "LiteralValue"} "kv2" => {"LiteralKey" => "LiteralValue"} "kv3" => {"Literalkey" => "LiteralValue"} "kv4" => {"LiteralKey" => "LiteralValue"}

        I noticed playing with this code that the output of .perl differs depending on if the colon is in front of the variable:

        say :%kv4.perl; #"kv1" => {"LiteralKey" => "LiteralValue"} say %kv4.perl; #{"LiteralKey" => "LiteralValue"}

        the colon seems to be plucking the Hash's name and creating a Pair with it.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://852927]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (9)
As of 2015-08-01 00:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (285 votes), past polls