develooper Front page | perl.perl6.users | Postings from January 2019

Re: I need hash inside a hash help

Thread Previous | Thread Next
From:
ToddAndMargo via perl6-users
Date:
January 11, 2019 19:18
Subject:
Re: I need hash inside a hash help
Message ID:
4f586037-bdb4-3c0d-aaff-fcc28137c709@zoho.com
On 1/11/19 11:12 AM, ToddAndMargo via perl6-users wrote:
> On 1/11/19 11:09 AM, Timo Paulssen wrote:
>> Hi Todd,
>>
>> the error you're getting comes from a closing quotation mark missing
>> after "Larry
>>
>> You will also need to give perl6 some hint that you want the list of
>> pairs to actually become a hash.
>>
>> To do that, I would recommend just putting a % in front of the ()
>>
>> The working code looks like this:
>>
>> perl6 -e 'my %Vendors=("acme" => %( "ContactName" => "Larry",
>> "AccountNo" => 1234 ) ); say %Vendors;'
>> {acme => {AccountNo => 1234, ContactName => Larry}}
>>
>> Hope that helps!
>>    - Timo
>>
>> On 11/01/2019 19:41, ToddAndMargo via perl6-users wrote:
>>> Hi All,
>>>
>>> How do I do a hash inside a hash?
>>>
>>> So far I have:
>>>
>>> $ p6 'my %Vendors=("acme" => ( "ContactName" => "Larry, "AccountNo" =>
>>> 1234 ) ); say %Vendors;'
>>> ===SORRY!=== Error while compiling -e
>>>
>>>
>>> I want to be able to have both a Contact Name and and AccountNo
>>> associated with each key in %Vendors.
>>>
>>>
>>> Many thanks,
>>> -T
> 
> 
> Hi Timo,
> 
> Thank you!
> 
> Ah man.  I took my best shot at it and got nailed by a stinkin' typo.
> 
> :'(
> 
> -T


Not to ask too stupid a question, but how do I get the values back out?

p6 'my %Vendors=("acme" => ( "ContactName" => "Larry", "AccountNo" => 
1234 ), "Ace" => ( "ContactName" => "Mo", "AccountNo" => "A102" ); say 
%Vendors<"Ace"<"ContactName">>;'

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About