Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Re2: split question

by BrowserUk (Patriarch)
on Sep 20, 2002 at 21:28 UTC ( [id://199635]=note: print w/replies, xml ) Need Help??


in reply to Re2: split question
in thread split question

That'll teach me to try and one-line my original solution.:(

For what it's worth, I didn't say that the last one would be more efficient, but I did say it would work ;(.

The original was

#! perl -sw use strict; my $var = "xxx:12345 yyy:54321 zzz:13245"; my $p=0; do { ($p=index($var, ':', $p+1 )) > -1 and print substr( $var, $p-3,3),$/; } while ($p > -1);

but I didn't like the double test against -1, so I tried to get rid of it. Don't know how I missed that it printed the extra one. A case of seeing what I wanted to see I guess.

I'm not that surprised that doing the looping inside the regex engine is more efficient than at user level. I'm guessing that it makes a single pass looking for fixed anchors like the : when the /g options is used. I am surprised how much more efficient it is.

Nice benchmark BTW. Something I need to get better at.


Cor! Like yer ring! ... HALO dammit! ... 'Ave it yer way! Hal-lo, Mister la-de-da. ... Like yer ring!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://199635]
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: (4)
As of 2024-04-25 10:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found