Skip to content

Instantly share code, notes, and snippets.

@masak
Last active December 17, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masak/5622039 to your computer and use it in GitHub Desktop.
Save masak/5622039 to your computer and use it in GitHub Desktop.
An update of https://gist.github.com/masak/158336 , four years later
sub only($rx) { /^ <$rx>+ $/ }
sub letters-with($n, $rx) { my $n1 = $n+1; /^ [<alpha>*] ** $n1 % <$rx> $/ }
sub letters-with-any($rx) { /^ [<alpha>*]+ % <$rx> $/ }
sub alnums-with($n, $rx) { my $n1 = $n+1; /^ [<alnum>*] ** $n1 % <$rx> $/ }
my @types =
'total ' => *,
' alphanumerics-only ' => only(/<alnum>/),
' digits-only ' => only(/\d/),
' letters-only ' => only(/<alpha>/),
' letters&u-score ' => letters-with-any(/'_'/),
' letters&digits ' => letters-with-any(/\d/),
' letters&1digit ' => letters-with(1, /\d/),
' letters&2digits' => letters-with(2, /\d/),
' letters&3digits' => letters-with(3, /\d/),
' letters&4digits' => letters-with(4, /\d/),
' letters&5digits' => letters-with(5, /\d/),
' letters&6digits' => letters-with(6, /\d/),
' with non-alnums ' => only(/<-alnum>/),
' 1 non-alnum ' => alnums-with(1, /<-alnum>/),
' 2 non-alnums ' => alnums-with(2, /<-alnum>/),
' 3 non-alnums ' => alnums-with(3, /<-alnum>/),
;
my @pwds = lines.map: { /^\d+\s+(\S+)/ or next; ~$0 };
for @types».kv -> $type, $matcher {
my $occ = +@pwds.grep($matcher);
printf "%-22s%3d (%6.2f%%)\n", $type, $occ, $occ/@pwds*100;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment