Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

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

by Aristotle (Chancellor)
on Aug 20, 2002 at 15: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 romping around the Monastery: (3)
As of 2020-02-29 14:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?










    Results (128 votes). Check out past polls.

    Notices?