Re: I need hash string help
On 1/11/19 6:51 PM, ToddAndMargo via perl6-users wrote: On 1/11/19 6:49 PM, Brad Gilbert wrote: $a is short for $a{'a','b'} This also happens in string literals my $a = { a => 1, b => 2 }; say "$a"; # 1 2 say "$a{'a','b'}"; # 1 2 A simple way to stop this is to add a backslash my $a = 'b' say "$a\"; # b You can also call methods on variables in string literals, as long as you use parentheses. my $a = Date.today; say "$a.year()-$a.month()-$a.day()"; # 2019-1-11 (Note that Date has a .-mm-dd() method) --- Looking at the message you just added: Perl 6 has a Version type. my $a = Version.new("12.3.4.1"); my $b = Version.new("111.3.4.1"); say $a before $b; # True Also there is syntax for creating a Version literal my $a = v12.3.4.1; my $b = v111.3.4.1; say $a before $b; # True There are useful methods on Versions my $a = v12.3.4.1; say $a.parts.perl; # (12, 3, 4, 1) On Fri, Jan 11, 2019 at 8:12 PM ToddAndMargo via perl6-users wrote: On 1/11/19 5:08 PM, ToddAndMargo via perl6-users 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; say $y;' Type check failed in assignment to $y; expected Str but got Any (Any) in block at -e line 1 $ p6 'my $x = "acme"; my Str $y; my %Vendors = ( acme => ContactName => "Larry" ); $y= %Vendors.Str; say $y;' Use of uninitialized value of type Any in string context. Methods .^name, .perl, .gist, or .say can be used to stringify it to something meaningful. in block at -e line 1 Many thanks, -T Figured out my booboo. I had to change from $PartsStr = "Hi $Manager," ~ "Account Number: $AccountNo" ~ to $PartsStr = "Hi " ~ $Manager ~ "," ~ "Account Number: " ~ $AccountNo ~ "" ~ Thank you! Come to think of it, I should have known better. I have these proofing line all over the place: PrintGreenErr( "WebPage = <<<" ~ $WebPage ~ ">>>\n" ); I need to start using single quotes with writing HTML. That way I will be forces to use ~ to add variables to the text.
Re: I need hash string help
On 1/11/19 6:49 PM, Brad Gilbert wrote: $a is short for $a{'a','b'} This also happens in string literals my $a = { a => 1, b => 2 }; say "$a"; # 1 2 say "$a{'a','b'}"; # 1 2 A simple way to stop this is to add a backslash my $a = 'b' say "$a\"; # b You can also call methods on variables in string literals, as long as you use parentheses. my $a = Date.today; say "$a.year()-$a.month()-$a.day()"; # 2019-1-11 (Note that Date has a .-mm-dd() method) --- Looking at the message you just added: Perl 6 has a Version type. my $a = Version.new("12.3.4.1"); my $b = Version.new("111.3.4.1"); say $a before $b; # True Also there is syntax for creating a Version literal my $a = v12.3.4.1; my $b = v111.3.4.1; say $a before $b; # True There are useful methods on Versions my $a = v12.3.4.1; say $a.parts.perl; # (12, 3, 4, 1) On Fri, Jan 11, 2019 at 8:12 PM ToddAndMargo via perl6-users wrote: On 1/11/19 5:08 PM, ToddAndMargo via perl6-users 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; say $y;' Type check failed in assignment to $y; expected Str but got Any (Any) in block at -e line 1 $ p6 'my $x = "acme"; my Str $y; my %Vendors = ( acme => ContactName => "Larry" ); $y= %Vendors.Str; say $y;' Use of uninitialized value of type Any in string context. Methods .^name, .perl, .gist, or .say can be used to stringify it to something meaningful. in block at -e line 1 Many thanks, -T Figured out my booboo. I had to change from $PartsStr = "Hi $Manager," ~ "Account Number: $AccountNo" ~ to $PartsStr = "Hi " ~ $Manager ~ "," ~ "Account Number: " ~ $AccountNo ~ "" ~ Thank you!
Re: I need hash string help
On 1/11/19 6:35 PM, Bruce Gray wrote: On Jan 11, 2019, at 7:08 PM, ToddAndMargo via perl6-users 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; say $y;' $ p6 'my $x = "acme"; my Str $y; my %Vendors = ( acme => ContactName => "Larry" ); $y= %Vendors.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"}; # Correct %Vendors{$company}; # Correct, if $company contains `acme` %Vendors;# Correct and most Perlish, if company is constant %Vendors;# 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`
Re: I need hash string help
$a is short for $a{'a','b'} This also happens in string literals my $a = { a => 1, b => 2 }; say "$a"; # 1 2 say "$a{'a','b'}"; # 1 2 A simple way to stop this is to add a backslash my $a = 'b' say "$a\"; # b You can also call methods on variables in string literals, as long as you use parentheses. my $a = Date.today; say "$a.year()-$a.month()-$a.day()"; # 2019-1-11 (Note that Date has a .-mm-dd() method) --- Looking at the message you just added: Perl 6 has a Version type. my $a = Version.new("12.3.4.1"); my $b = Version.new("111.3.4.1"); say $a before $b; # True Also there is syntax for creating a Version literal my $a = v12.3.4.1; my $b = v111.3.4.1; say $a before $b; # True There are useful methods on Versions my $a = v12.3.4.1; say $a.parts.perl; # (12, 3, 4, 1) On Fri, Jan 11, 2019 at 8:12 PM ToddAndMargo via perl6-users wrote: > > On 1/11/19 5:08 PM, ToddAndMargo via perl6-users 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; say $y;' > > Type check failed in assignment to $y; expected Str but got Any (Any) > >in block at -e line 1 > > > > > > $ p6 'my $x = "acme"; my Str $y; my %Vendors = ( acme => ContactName => > > "Larry" ); $y= %Vendors.Str; say $y;' > > Use of uninitialized value of type Any in string context. > > Methods .^name, .perl, .gist, or .say can be used to stringify it to > > something meaningful. > >in block at -e line 1 > > > > > > Many thanks, > > -T > > Figured out my booboo. I had to change from > > $PartsStr = >"Hi $Manager," ~ >"Account Number: $AccountNo" ~ > > to > > $PartsStr = >"Hi " ~ $Manager ~ "," ~ >"Account Number: " ~ $AccountNo ~ "" ~
Re: I need hash string help
On 1/11/19 6:23 PM, Tom Browder wrote: On Fri, Jan 11, 2019 at 20:15 ToddAndMargo via perl6-users mailto:perl6-users@perl.org>> wrote: ... > $p6 'my $x = "acme"; my %Vendors = ( acme => { ContactName => "Larry", > AccountNo => 1234 } ); my Str $y = %Vendors{$x}.Str; say $y;' In my experience, it helps often to avoid using strict typing unless really needed. Best regards, -Tom There are instances where I get myself in a mess if I do not type things. So some I do and some I don't. Keeps me out of trouble. Most times now I do. One instance where I fly back and forth between strings and integers is where I am checking revisions. Is "12.3.4.1" newer than "111.3.4.1"? I do a split on the variable at the dots, turn the string fragments into integers and test each position one at a time. The code was a nightmare until I started using typing. That found all my mistakes with alacrity. Code came out real elegant after that. I was pleased with my ingenuity. I use .Str and .Int a lot now-a-days too. Even if not necessary, it is for maintainability when there is a conversion going on that I have forgotten about. In the question I posted the value had to absolutely be a Str and nothing else. If anyone added to it and was not properly turning other things into a string, I wanted it to instantly fail. The Str in question was a HTML that was passing a parts order to Thunderbird to mail to my vendors.
Re: I need hash string help
> On Jan 11, 2019, at 7:08 PM, ToddAndMargo via perl6-users > 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; say $y;' > $ p6 'my $x = "acme"; my Str $y; my %Vendors = ( acme => ContactName => > "Larry" ); $y= %Vendors.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"}; # Correct %Vendors{$company};# Correct, if $company contains `acme` %Vendors;# Correct and most Perlish, if company is constant %Vendors; # 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)
Re: I need hash string help
On Fri, Jan 11, 2019 at 20:15 ToddAndMargo via perl6-users < perl6-users@perl.org> wrote: ... > $p6 'my $x = "acme"; my %Vendors = ( acme => { ContactName => "Larry", > AccountNo => 1234 } ); my Str $y = %Vendors{$x}.Str; say $y;' In my experience, it helps often to avoid using strict typing unless really needed. Best regards, -Tom
Re: I need hash string help
On 1/11/19 5:59 PM, Tom Browder wrote: On Fri, Jan 11, 2019 at 19:09 ToddAndMargo via perl6-users 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} ~ "\t" ~ %Vendors{$x};' $p6 'my $x = "acme"; my %Vendors = ( acme => { ContactName => "Larry", AccountNo => 1234 } ); my Str $y = %Vendors{$x}.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` (HTML "Break") being mistaken for something else in a string assignment. Breaking the variables apart with `$var ~ ""` 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 ~~
Re: I need hash string help
On 1/11/19 5:08 PM, ToddAndMargo via perl6-users 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; say $y;' Type check failed in assignment to $y; expected Str but got Any (Any) in block at -e line 1 $ p6 'my $x = "acme"; my Str $y; my %Vendors = ( acme => ContactName => "Larry" ); $y= %Vendors.Str; say $y;' Use of uninitialized value of type Any in string context. Methods .^name, .perl, .gist, or .say can be used to stringify it to something meaningful. in block at -e line 1 Many thanks, -T Figured out my booboo. I had to change from $PartsStr = "Hi $Manager," ~ "Account Number: $AccountNo" ~ to $PartsStr = "Hi " ~ $Manager ~ "," ~ "Account Number: " ~ $AccountNo ~ "" ~
Re: I need hash string help
On Fri, Jan 11, 2019 at 19:09 ToddAndMargo via perl6-users < 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