Benchmarks, first the code: (GAK! See post from dchetlin)
use strict; use Benchmark qw(cmpthese); my @x; $x[0]= "mark " x 35; $x[1]= "asdfasdfasdfasdfasdf " x 35; $x[2]= "as " x 31; $x[3]= "asdfasdfasdfasdfasdfasdf " x 100; $x[4]= "asdfasdfasdfasdfasdfasdf " x 10; # http://www.cpan.org/doc/manual/html/pod/perlfunc/index.html # # Well, that was no help... fricking http conventions # cmpthese (1000000, { 'regexp' => ' foreach (@x) { /^((?:\S+\s*){1,30})/; print $1; } ', 'split_join' => ' foreach (@x) { print join ( " ", (split " ", $_,31)[0..29] ); } ', 'for_index_substr' => ' foreach (@x) { my $ind = index ($_, " "); for (0..29) { last if $ind == -1; $ind = index $_, " ", $ind; } print substr($_,0,$ind); } ', } );

and now the results (basically, a huge fricking waste of time, we are talking a MILLION reps on p166 here.)

                    Rate       split_join for_index_substr           regexp
split_join       69061/s               --              -7%              -7%
for_index_substr 73910/s               7%               --              -1%
regexp           74627/s               8%               1%               --
### second run, no changes... hmmm....
                    Rate for_index_substr       split_join           regexp
for_index_substr 68027/s               --              -9%              -9%
split_join       74349/s               9%               --              -0%
regexp           74516/s              10%               0%               --

At those rates, any of those would likely be waiting on the harddrive to feed them data. My dataset is about 3.5kB so that means 232MB/s feedrate on the WORST run there and 255MB/s on the best. =) Do it anyway you want. Not going to matter, not one iota, in the long run.

--
$you = new YOU;
honk() if $you->love(perl)


In reply to Re: 30 Spaces- 1 question by extremely
in thread 30 Spaces- 1 question by AgentM

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.