my @sets_of_six = ( $s =~ m{ (.{6}) }xmsg );
| [reply] [d/l] |
[0] Perl> print $string;;
2648117951505438300028047571976236505346
@sets_of_six = ( $string =~ m{ (.{6}) }xmsg );;
print for @sets_of_six;;
264811
795150
543830
002804
757197
623650
Note the missing last four characters. Can be fixed (and the parens are extraneous):
@sets_of_six = $string =~ m{ (.{0,6}) }xmsg;;
print for @sets_of_six;;
264811
795150
543830
002804
757197
623650
5346
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [d/l] [select] |
According to Re^4: Breaking up a string?, "length is a multiple of 6". If it's not a multiple of six, the OP hasn't specified what the correct behavior is anyway (though maybe you could test against the algorithm described in Re^2: Breaking up a string?).
Thanks for pointing out the extraneous parentheses.
| [reply] |
If you got your six characters, why did you perform that reverse - 6 times chop - reverse operation on it? Can't you post a little example code that runs, some example input and the result you get, with an explanation on how your result differ from what you want? | [reply] |
Because I then wanted to get the next 6 chars, then the 6 after that, until the end of the string (length is a multiple of 6).
| [reply] |
I'm very unsure about what you really want, but this capture my understanding of what you ask for:
use strict; use warnings;
my $input = '1234562234563334564444565555566789';
my @sets_of_six;
while (length $input > 6){
my $front = substr($input, 0, 6);
$input = substr($input, 6);
push @sets_of_six, $front;
}
push @sets_of_six, $input if length $input > 0;
use Data::Dumper;
print Dumper( @sets_of_six );
Now, that is a rather naive solution, it's not very effective, nor is it very perl'ish, but I think you might understand what is happening. Is it faintly aproaching your question? hth | [reply] [d/l] |