chipmonk has asked for the wisdom of the Perl Monks concerning the following question:

Trying to read in a file and split into to perform data checks. Format of data is: xxxxx "name " xxx xxxxx "name " xxx xxx xxxx xxx Using </ /> with two space works except some name are alpha 2 so the alpha and 2 are broken up instead of the name being alpha 2 Any advise is appreciated.

Replies are listed 'Best First'.
Re: Split Malfunction
by toolic (Bishop) on Oct 23, 2015 at 13:51 UTC
    If you want to preserve whitespace inside double quotes, you can use Text::CSV instead of split:
    use warnings; use strict; use Text::CSV; use Data::Dumper; my $str = q(xxxxx "alpha 2" xxx xxxxx "name " xxx xxx xxxx xxx); my $csv = Text::CSV->new( { binary => 1, sep_char => ' '} ) # should +set binary attribute. or die "Cannot use CSV: ".Text::CSV->error_diag (); my $status = $csv->parse($str); # parse a CSV string into fiel +ds my @columns = $csv->fields(); # get the parsed fields print Dumper(\@columns); __END__ $VAR1 = [ 'xxxxx', 'alpha 2', 'xxx', 'xxxxx', 'name ', 'xxx', 'xxx', 'xxxx', 'xxx' ];