Hole type: subroutine
Write a subroutine which, given a string consisting entirely of
hexadecimal digits, converts pairs of digits to their ASCII character
equivalents and returns the result as a list of characters. The
hexadecimal digits A-F may appear in upper or lower case. There will be
an even number of digits in the string.
e.g.
5065726c206861636b6572
->
('P', 'e', 'r', 'l', ' ', 'h', 'a', 'c', 'k', 'e', 'r')
Code | Length |
---|---|
sub hole {grep$_=$_&&chr hex,split/(..)/,pop} | 34 |
sub hole {$_=pop;s/../chr hex$&/ge;/./g} | 29 |
sub hole {map{chr hex}pop=~/../g} | 22 |
sub hole {split//,pack'H*',@_} | 19 |
sub hole {(pack'H*',@_)=~/./g} | 19 |
sub hole {$_=pack'H*',@_;/./g} | 19 |
Ronald came up with this hole because he wanted to be clever with split and grep. Then someone posted one of the pack solutions. Doh! But he redeemed himself slightly by coming up with another of the pack variants shown above.