On Jun 6, Accountant Bob said:

>How about this: (the same but "unrolled")
>
>my @elements;
>push @elements, $1 while
>   /\G\s*"([^\\"]*(?:\\["\\][^\\"]*)*)"/gc or
>   /\G\s*'([^\\']*(?:\\['\\][^\\']*)*)'/gc or
>   /\G\s*([^\s'"]\S*)/gc;
>
>is there actually an advantage to doing this?

Yes, as is discussed (at length) in J. Friedl's "Mastering Regular
Expressions".  In fact, matching quoted strings in unrolled form is a very
big part of his chapter on crafting regexes.

Unrolling the loop can be a timesaver, since .*? can be slowish.

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun.
Are you a Monk?  http://www.perlmonks.com/     http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc.     http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter.         Brother #734
**      Manning Publications, Co, is publishing my Perl Regex book      **

Reply via email to