I don't know if split is or isn't optimized; I just have a story related to split to share.

In our code library, we have a function named rand_split, which looks like this:

	sub rand_split {
	    my ($sep, $string) = @_;
	    my ($element, $char, $pos, $end, @array);

	    $end = length($string);
	    $element = "";
            for ($pos = 0; $pos < $end; $pos++) {
	        $char = substr($string, $pos, 1);
	        if ($char eq $sep) {
	            push (@array, $element);
	            $element = "";
	        } else {
	            $element = $element . $char;
	        }
	    }
	    push (@array, $element);
	    return (@array);
	}

rand_split was written by a guy named Rand a couple of programmer generations ago. We don't know why he reimplimented it; We don't know a lot of things about it. However, another programmer from around that generation claimed that "If he did it, there must have been a reason." It's not like he didn't know split didn't exist, meaning he purposefully reinvented a wheel. As nearly as we can tell, it walks like split and talks like split; Therefore, it is split. It's used in one script these days, and probably zero in the very near future, but I think we've kept it around mainly for gag value, giving every new generation of programmer something to wonder about.


In reply to Re: is split optimized? by bs
in thread is split optimized? by Anonymous Monk

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.