thx for pointing out. what about
'regexpad' => sub { # padding the string my $padding = 8 - length($str%8) if length($str%8); #has to be 8 - m +odulo not modulo, thx johngg $str .= "x" x $padding; # dividing the string in parts of 8 chars my @arr = $str =~ /(........)/g; #remove padding $arr[-1] = substr($arr[-1],-$padding); }
although its a bit slower than the other 2 regex solutions
Rate split_pos grep_split substr_map regexpad regexo re +gex substr_loop unpack split_pos 5841/s -- -64% -70% -75% -76% - +76% -79% -80% grep_split 16129/s 176% -- -17% -30% -33% - +34% -42% -45% substr_map 19531/s 234% 21% -- -15% -19% - +20% -30% -33% regexpad 22936/s 293% 42% 17% -- -5% +-6% -17% -22% regexo 24038/s 312% 49% 23% 5% -- +-1% -13% -18% regex 24272/s 316% 50% 24% 6% 1% + -- -13% -17% substr_loop 27778/s 376% 72% 42% 21% 16% +14% -- -5% unpack 29240/s 401% 81% 50% 27% 22% +20% 5% --
Edit: corrected padding

--
"WHAT CAN THE HARVEST HOPE FOR IF NOT THE CARE OF THE REAPER MAN"
-- Terry Pratchett, "Reaper Man"


In reply to Re^2: Splitting a string to chunks by Fengor
in thread Splitting a string to chunks by spurperl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.