in reply to How to slice complicated string into an array

Is that CSV? Then use Text::CSV / Text::CSV_XS.

use warnings; use strict; my $line = q{"word1",word2,"word3,word4"}; use Text::CSV; my $csv = Text::CSV->new({binary=>1,auto_diag=>2}); $csv->parse($line); use Data::Dumper; print Dumper( [ $csv->fields() ] ); __END__ $VAR1 = [ 'word1', 'word2', 'word3,word4' ];

Replies are listed 'Best First'.
Re^2: How to slice complicated string into an array
by theNeuron (Novice) on Feb 26, 2016 at 12:15 UTC
    Yes, that is csv and I should have mentioned it. That module is not part of distribution (at least to the perl I have) which would limit the script usability in our environment. But thank you for the pointer.

      As a core module Text::ParseWords is convenient for simple cases.

      # perl use strict; use Text::ParseWords; use Data::Dumper; my $str = '"word1",word2,"word3,word4"'; my @words = quotewords(',', 0, $str); print Dumper \@words;
      poj