Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^4: Optimizing existing Perl code (in practise)

by Aristotle (Chancellor)
on Aug 20, 2002 at 15:27 UTC ( [id://191479]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: Optimizing existing Perl code (in practise)
in thread Optimizing existing Perl code (in practise)

No they don't. For starters, your split produces and assigns at least three values in every case the pattern matches. The difference in their effects may be irrelevant to your specific application, but that doesn't make them equivalent. Taking that into consideration from the start, you shouldn't have needed to benchmark them to predict the outcome.

If you want a regex version that works meaningfully similar to the split, it would have to look something like this: my @a = ($foo =~ /(?:\s+)?(.*?)(?=\s)/g); (Because your pattern is as simple as \s+, you can formulate a regex version like my @a = ($foo =~ /(\S+)/g); but that doesn't generalize to splitting at foo(?:bar|baz)? )

Makeshifts last the longest.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-24 06:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found