Perl split list on commas except when within brackets?

前端 未结 4 925
庸人自扰
庸人自扰 2021-01-02 11:09

I have a database with a number of fields containing comma separated values. I need to split these fields in Perl, which is straightforward enough except that some of the va

4条回答
  •  孤独总比滥情好
    2021-01-02 11:54

    Try this:

    my $s = q{recycling, environmental science, interdisciplinary (e.g., consumerism, waste management, chemistry, toxicology, government policy, and ethics), consumer education};
    
    my @parts = split /(?![^(]+\)), /, $s;
    

提交回复
热议问题