Michael Louie Loria wrote:

> Hello,
> 
> I have a problem with the split function.
> 
> string
> - - -
> one "two three" "four five" six seven
> 
> should be split to
> - - -
> one
> two three
> four five
> six
> seven
> 
> 
> string
> - - -
> one two three four five six seven
> 
> should be split to
> - - -
> one
> two
> three
> four
> five
> six
> seven
> 
> 
> the difference is the string enclosed with "  " is considered as 1
> string even with spaces.

As mentioned - you could find a module, but this should work for your case:

use strict;
use warnings;

$_ = 'one "two three" "four five" six seven';

s/"([^"]+) ([^"]+)"/$1\000$2/g; # replace embedded spaces with nulls

my @a = split / +/;

foreach (@a) {
        s/\000/ /g;     # restore embedded spaces
        print "$_\n";
}

__END__

-- 
  ,-/-  __      _  _         $Bill Luebkert    Mailto:[EMAIL PROTECTED]
 (_/   /  )    // //       DBE Collectibles    Mailto:[EMAIL PROTECTED]
  / ) /--<  o // //      Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_    http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to