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"
-
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.
|