>>>>> "Ondrej" == Ondrej Par <[EMAIL PROTECTED]> writes:
Ondrej> my $line = 'whatever "this" \'line is\'';
Ondrej> $line =~ s/\s*$//;
Ondrej> my @parts;
Ondrej> while ($line ne '') {
Ondrej> if ($line =~ m/^\s*(['"])((?:(?:\\.)|[^\\])*?)\1(.*)/) {
Ondrej> push @parts, $2;
Ondrej> $line = $3;
Ondrej> } elsif ($line =~ m/^\s*(\S+)(.*)/) {
Ondrej> push @parts, $1;
Ondrej> $line = $2;
Ondrej> }
Ondrej> }
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.
--
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!