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

Re: I need hash string help

Thread Previous
From:
ToddAndMargo via perl6-users
Date:
January 12, 2019 02:38
Subject:
Re: I need hash string help
Message ID:
559189d1-c0e2-03d1-f806-be7ade00ff2e@zoho.com
On 1/11/19 6:23 PM, Tom Browder wrote:
> On Fri, Jan 11, 2019 at 20:15 ToddAndMargo via perl6-users 
> <perl6-users@perl.org <mailto:perl6-users@perl.org>> wrote:
> ...
>  > $p6 'my $x = "acme"; my %Vendors = ( acme => { ContactName => "Larry",
>  > AccountNo => 1234 } ); my Str $y = %Vendors{$x}<ContactName>.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.

Thread Previous


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