in reply to Split a string into a list of lists
Output:use strict; use warnings; my $string = "BEHACJBDLCENADFEGOFHQAGIHJRBIKJLSCKMLNTDMOFNPOQTGPRIQSKRTMPS"; my @result = ( [ 0, 0, 0, 0, ], # map [ 0, map $_ -= 64, unpack 'C*', $_ ], # -= is pointless map [ 0, map $_ - 64, unpack 'C*', $_ ], unpack '(a3)*', $string ); # Print the results for my $i (1..20) { for my $j (1..3) { print sprintf("%02d", $result[$i][$j]) . " "; } print "\n"; }
Update: $_ -= 64 in map statement is pointless waste of computrons. Changed to $_ - 64 per oshalla's reply below.02 05 08 01 03 10 02 04 12 03 05 14 01 04 06 05 07 15 06 08 17 01 07 09 08 10 18 02 09 11 10 12 19 03 11 13 12 14 20 04 13 15 06 14 16 15 17 20 07 16 18 09 17 19 11 18 20 13 16 19
|
|---|