develooper Front page | perl.perl6.users | Postings from October 2017

Tip: hash indexing

Thread Next
From:
ToddAndMargo
Date:
October 2, 2017 20:54
Subject:
Tip: hash indexing
Message ID:
0c7f606f-27f1-d056-6953-f5e03a3162ba@zoho.com
Hi All,

I created a keeper not on hash indexing.  I though
maybe you guys would find it interesting, if for nothing
else, for the syntax used

-T


Perl6: Indexing a hash:

<code>
#!/usr/bin/env perl6

#`{
   Hashes do not print in the order they are created.  it is a Perl 6 thing.
   To overcome this, create an index of the hash.
}

my @SmtpIndex =
    qw[ DebugTrace smtp port username password from to Subject Text 
FileName ];

my %Smtp =
   [ "{ @SmtpIndex[0] }" => "1",
     "{ @SmtpIndex[1] }" => "smtps://smtp.zoho.com",
     "{ @SmtpIndex[2] }" => "465",
     "{ @SmtpIndex[3] }" => 'larry@zoho.com',
     "{ @SmtpIndex[4] }" => "NaYukYukYuk",
     "{ @SmtpIndex[5] }" => 'larry@zoho.com',
     "{ @SmtpIndex[6] }" => @['curly@zoho.com','mo@zoho.com'],
     "{ @SmtpIndex[7] }" => "Stooges",
     "{ @SmtpIndex[8] }" => "Certainly!",
     "{ @SmtpIndex[9] }" => @[""] ];

for @SmtpIndex -> $key { printf "%10s = %s\n", "$key", "%Smtp{$key}"; }
</code>


$ HashIndexTest.pl6
DebugTrace = 1
       smtp = smtps://smtp.zoho.com
       port = 465
   username = larry@zoho.com
   password = NaYukYukYuk
       from = larry@zoho.com
         to = curly@zoho.com mo@zoho.com
    Subject = Stooges
       Text = Certainly!
   FileName =

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