For question 1, whatever happened to coding things the old-fashioned way?

Maybe because if we wanted to write verbose error prone code we would stick to C where it would at least be fast? I mean seriously do you really think your solution is easier to read or understand than

@codons = unpack "(a3)*",$string;

and

my @runs; push @runs,$1 while $string=~/((.)\2*)/gs;

I mean your code has about 5 times the informational density than mine. That says to me that there is 5 times more places to make silly errors and its 5 times more likely that some maintainer will misunderstand and break the code. And as a bonus the perlish code is going to be MUCH faster. I'll leave benchmarking it to you, but I think youll be unpleasantly surprised at how much slower your variants are.

Even if you did for some weird reason want to avoid the natural perl way to do these things the code you have is less than desirable. Three arg for loop when you could have used for LIST and avoided potential fencepost errors etc.

And to prove my point a close inspection of your second snippet reveals a subtle error: $start=pos; is wrong. It should $pos as pos is a special keyword used by the regex engine. A mistake that wouldn't have occured had you not been trying to write C code in Perl.

---
$world=~s/war/peace/g


In reply to Re^2: Puzzlement in Splitsville (use the force luke) by demerphq
in thread Puzzlement in Splitsville by tlm

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.