Skip to content

Instantly share code, notes, and snippets.

@cognominal
Last active December 11, 2015 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cognominal/3aed2e52f2cecce1d653 to your computer and use it in GitHub Desktop.
Save cognominal/3aed2e52f2cecce1d653 to your computer and use it in GitHub Desktop.
sha1 hash
subset Sha1 of Str where *.chars == 40 and m:i/<[A..F 0..9]>/;
class Sha1H does Associative {
has %!h;
method AT-KEY(Sha1 $_) { %!h{ .lc } };
method ASSIGN-KEY(Sha1 $_, $v) { %!h{ .lc } = $v }
}
my %h is Sha1H;
my $sha1 = '64B0F6C3681E428CCE2EB830B05F27B3D7ED643E';
say $sha1.chars;
%h{$sha1} = 'a';
say %h{$sha1};
%h<a> = 'b'; # fail here because not Sha1 :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment