>>>>> "Ondrej" == Ondrej Par <[EMAIL PROTECTED]> writes:

Ondrej> On Wednesday 06 June 2001 18:19, Randal L. Schwartz wrote:
>> That's a good approach, but maybe this one is more straightforward:
>> 
>> $_ = q{whatever "this" 'line is'};
>> 
>> my @elements;
>> push @elements, $1 while
>> /\G\s*"(.*?)"/gc or
>> /\G\s*'(.*?)'/gc or
>> /\G\s*(\S+)/gc;
>> 
>> print map "<<$_>>", @elements;
>> 
>> The use of scalar /\G...../gc to inchworm along a string is a powerful
>> technique.

Ondrej> Yes, this is better. With one exception - you're not handling \' and \" (but 
Ondrej> this can be copied from previous example).

my @elements;
push @elements, $1 while
  /\G\s*"((?:[^\\"]|\\"|\\\\)*)"/gc or
  /\G\s*'((?:[^\\']|\\'|\\\\)*)'/gc or
  /\G\s*([^\s'"]\S*)/gc;

Leaving undefined something like \X as malformed. :)

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

Reply via email to