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

Re: I need hash string help

Thread Previous | Thread Next
From:
ToddAndMargo via perl6-users
Date:
January 12, 2019 02:14
Subject:
Re: I need hash string help
Message ID:
eb061857-60c8-ea5c-8f28-7f5cceb068b9@zoho.com
On 1/11/19 5:59 PM, Tom Browder wrote:
> 
> On Fri, Jan 11, 2019 at 19:09 ToddAndMargo via perl6-users 
> <perl6-users@perl.org <mailto:perl6-users@perl.org>> wrote:
> 
>     Now what am I doing wrong?  I need to convert the value in a
>     hash to a string:
> 
>     $ p6 'my $x = "acme"; my Str $y; my %Vendors = ( acme => ContactName =>
>     "Larry" ); 
> 
> 
> Try eliminating “acme =>” for a starter.
> 
> -Tom

Hi Tom,

It was a shortened version of a lager has within a hash.

$ p6 'my $x = "acme"; my %Vendors = ( acme => { ContactName => "Larry", 
AccountNo => 1234 } ); say %Vendors{$x}<ContactName> ~ "\t" ~ 
%Vendors{$x}<AccountNo>;'

$p6 'my $x = "acme"; my %Vendors = ( acme => { ContactName => "Larry", 
AccountNo => 1234 } ); my Str $y = %Vendors{$x}<ContactName>.Str; say $y;'

I just shortened it to test syntax.  I need the value of the hash to 
going into a string.  It did but the error message I got back
confused the heck out of me.

       Type Str does not support associative indexing.

Made me think something was wrong with the hash.  The hash
and was fine.

I found it by disregarding the error message and looking for
ANYTHING I had changed.

My error turned out be `$var<br>` (HTML "Break") being mistaken
for something else in a string assignment.  Breaking the
variables apart with `$var ~ "<br>"` fixed it.

Thank you for the help anyway.  There is a lot of great folks
on this list.  :-)

-T




-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Computers are like air conditioners.
They malfunction when you open windows
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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