Skip to content

Commit f227573

Browse files
committed
Modernize Fletcher.pl
Just adding P6-isms here and there.
1 parent e5eac13 commit f227573

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

module-management/Fletcher.pl

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,37 +32,27 @@ ($module,%meta)
3232
return $filename ~ "--0";
3333
}
3434
sub strencode($str) {
35-
return $str.subst(/(<-alpha -[_:]>)/,{ charencode($0) },:g);
35+
return $str.subst(/(<-alpha -[:]>)/,{ charencode($0) },:g);
3636
}
3737
sub charencode($char) {
38-
my ($url,$hex) = ('',int2hex(ord $char));
38+
my ($url,$hex) = ('',$char.fmt("%02x"));
3939

40-
$hex = '0' ~ $hex if ($hex.chars % 1);
4140
while $hex.chars {
42-
$url ~= '%' ~ $hex.substr(0,2);
43-
$hex = $hex.substr(2);
41+
$url ~= '%' ~ $hex.substr(0,2);
42+
$hex = $hex.substr(2);
4443
}
4544
return $url;
4645
}
47-
sub int2hex($val is rw) {
48-
my $hex = '';
49-
while $val {
50-
my $tmp = $val % 16;
51-
$val = int($val/16);
52-
$hex = ($tmp < 10 ?? $tmp !! chr (97 - 10 + $tmp)) ~ $hex;
53-
}
54-
return $hex;
55-
}
5646
sub fletcher16($str) {
5747
my ($A,$B) = (0,0);
5848
for map { .ord }, $str.comb -> $val {
5949
if $val > 255 {
60-
$A = ($A + int($val/255)) % 255;
50+
$A = ($A + $val div 255) % 255;
6151
$B = ($B + $A) % 255;
6252
}
6353
$A = ($A + $val % 255) % 255;
6454
$B = ($B + $A) % 255;
6555
}
66-
return sprintf "%04s", int2hex($A*256 + $B);
56+
return ($A*256 + $B).fmt("%04x");
6757
}
6858

0 commit comments

Comments
 (0)