This method invokes an on-the-fly subroutine with the string split into characters as the arguments. This allows you to shift groups of three letters at a time using a map, with a second map to do the subtraction, all inside an array ref. constructor which is pushed onto the return array.
use strict; use warnings; my $string = q{BEHACJBDLCENADFEGOFHQAGIHJRBIKJLSCKMLNTDMOFNPOQTGPRIQSKRTMPS}; my @array = sub { my @arr = ( [] ); push @arr, [ map ord( $_ ) - 64, map shift, 1 .. 3 ] while @_; return @arr; }->( split m{}, $string ); printf qq{%02d %02d %02d\n}, @$_ for @array[ 1 .. $#array ];
The results match yours and I think the numbers may very well have something to do with the England cricketer's recent batting form :-(
Cheers,
JohnGG
In reply to Re: Split a string into a list of lists
by johngg
in thread Split a string into a list of lists
by W1SDM
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |