Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: Puzzlement in Splitsville (use the force luke)

by demerphq (Chancellor)
on Jun 21, 2005 at 11:01 UTC ( [id://468624]=note: print w/replies, xml ) Need Help??


in reply to Re: Puzzlement in Splitsville
in thread Puzzlement in Splitsville

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

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://468624]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-25 12:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found