Replace commas with pipes, but not the commas enclosed in double quotes

后端 未结 3 1121
庸人自扰
庸人自扰 2021-01-05 13:11

I have a record set that looks like this

\"BOSW0001\",\"Mr\",\"Wayne\",\"Boswell\",\"Wayne,Jessica & Lyn\",\"31          


        
3条回答
  •  南方客
    南方客 (楼主)
    2021-01-05 14:03

    Just for the sake of TIMTOWTDI, here is an example using the core module Text::ParseWords.

    #!/usr/bin/env perl
    
    use strict;
    use warnings;
    
    use Text::ParseWords 'parse_line';
    
    foreach my $line () {
      print join '|', parse_line(',', 1, $line);
    }
    
    __DATA__
    "BOSW0001","Mr","Wayne","Boswell","Wayne,Jessica & Lyn","31 Baker St"
    "ELLI0007","Mrs","Bronwyn","Elliott","Bronwyn, Paul & Arianne","98A Dandaraga Rd"
    "KENN0001","Mr","Leigh","Kenning","Leigh & Beth,Cole","22 Lake St"
    

提交回复
热议问题