On 1/11/19 6:35 PM, Bruce Gray wrote:


On Jan 11, 2019, at 7:08 PM, ToddAndMargo via perl6-users 
<perl6-us...@perl.org> wrote:

Hi All,

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" ); 
$y= %Vendors<ContactName>; say $y;'
$ p6 'my $x = "acme"; my Str $y; my %Vendors = ( acme => ContactName => "Larry" ); 
$y= %Vendors<ContactName>.Str; say $y;’
—snip—

This has nothing to do with string conversion.

Compared to the previous email thread, two problems have been introduced:

1. The curly braces from around the second-level hash are now missing, changing 
from
     CompanyName => { SomeKey => "foo" ... }
to
     CompanyName =>   SomeKey => "foo" ...
So, you no longer have a HashOfHashes, you have a HashOfPair (singular Pair, 
not plural Pairs), so while this syntax can technically be made to work, it 
would only work with a single key, which is pointless.

2. The first level (company name?) of your HashOfHashes is no longer 
dereferenced. I see that you populated `$x`, but did not ever use it.
        %Vendors{"acme"}<ContactName>;                  # Correct
        %Vendors{$company}<ContactName>;          # Correct, if $company 
contains `acme`
        %Vendors<acme><ContactName>;                # Correct and most Perlish, 
if company is constant
        %Vendors<ContactName>;                            # Bad; will never work 
unless you happen to have a company really named "ContactName”. (Even then, you would 
get the whole first-level hash)

UPDATE: Just before sending this, I peeked ahead at the exchange between Tom 
Browder and yourself. I think that you hit a snag, and constructed an example 
that showed what you thought was the snag, but was really a new set of problems 
that exists only in your example. FYI, every time that I have made this 
mistake, it was always due to my creating an example from scratch, instead of 
slowly massaging the real problem code down into a minimal form for public 
discussion. YMMV.

I am glad you and Tom resolved your problem before I could `send`, but I did 
not want this post to go to waste.

—
Hope this helps,
Bruce Gray (Util of PerlMonks)


That is exactly what happened.

What is happening is that I am copy and pasting five columns
(and any number of rows) from my parts database to the
clipboard, reading the clipboard into my perl code, writing
an letter in HTML to my vendor with the parts to be ordered,
and then sending it back to the clipboard for pasting into
Thunderbird.

Each parts group (four lines and a blank line) has an alternate
color.  Quantities greater than one are bolded.  (I haven't had
them goof the quantity since I bolded greater than 1.)

My company account number is at the top and bolded.  The letter
includes my salesman's name.  Enough HTML to make you scream.
I should use single quote when writing in HTML. That would
force me to separate variables with ~

I have had them goof my account number.  They don't
like to ask for my account number as we are suppose
to be good buddies and they are suppose to know me
by heart.  Ha!  So now I have included my account number
as well.

By the way, if anyone is interested, when reading columns from a spreadsheet off the clipboard, the columns are delimited by a
tab `\t`

Reply via email to