I agree with moritz in that you might want to use another approach now that you have your string split into an array.
This sounds like it might be a job for List::MoreUtils:
use strict;
use warnings;
use List::MoreUtils qw(natatime);
my $str="AJKDHAKAESRADADKLASRRASDASDKASEKA";
my @ar = split '(?<=[KR](?!P))', $str; #to split where i ever i see a
+K or R.
print "ar: @ar\n";
my @new;
my $it = natatime 2, @ar;
while (my @vals = $it->()) {
push @new, (join '', @vals);
}
print "new: @new\n";
prints:
ar: AJK DHAK AESR ADADK LASR R ASDASDK ASEK A
new: AJKDHAK AESRADADK LASRR ASDASDKASEK A
Is that what you are looking for for question #1? If so,
I think you can use the natatime function to also solve #2.
Update: OP has been updated.
Also, it is best if you just put code snippets inside <code> tags, rather than the bulk of your question.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|