Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

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

by Aristotle (Chancellor)
on Aug 20, 2002 at 11:27 UTC ( #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
Node Status?
node history
Node Type: note [id://191479]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (10)
As of 2019-06-18 11:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Is there a future for codeless software?



    Results (81 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 18:53 UTC) Welcome new users!