Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
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"]]]

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?
Discipulus bad people + good tool < normal people + decent tool
[Discipulus]: php does not suck anymore?
[ambrus]: Discipulus: I'm not sure, but it certainly doesn't suck as much as it's used to. it's like C++, it sucks because people still recursively learn from twenty year old PHP examples,
[ambrus]: and they try to use the obsolete features that PHP has to support only for compatibility with old scripts. C++ and PHP both have the problem that people can't forget the past, because when they google "PHP" plus the problme they want to solve, they find b
[ambrus]: ad code examples.
[ambrus]: I'm not trying to recommend PHP, but I think it has way too bad a name because of its past.
[ambrus]: This is different from MS Word, which was already a good editor in the pre-unicode days (in word for windows versions 2 and 6, which ran on windows 3 but also on windows 95), only it wasn't trying to solve the task of writing maths papers back then.
[Discipulus]: ah ok, sounds reasonable; with no fear: Perl all life long
[ambrus]: Mind you, LaTeX is currently still useful for writing math paper or snippet content without styling in such a way that the
[ambrus]: formatting conventions of a journal or website can be quickly applied to it, and MS Office and LibreOffice has not quite solved this (although it's better for this than it used to be),

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (11)
As of 2017-09-26 11:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (293 votes). Check out past polls.

    Notices?