Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2024-04-23 09:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found