Home > Software design >  How to substitute values ​enclosed in double quotes
How to substitute values ​enclosed in double quotes

Time:05-20

I need to substitute values ​​enclosed in double quotes. The goal is to replace commas with question marks and replace double quotes surrounded by double quotes with hyphens.

CodePudding user response:

use Text::ParseWords;

my $dlm = ","; # 区切り文字を定義

open(RH, "<", "from.csv");
open(WH, ">", "to.csv");
while(<RH>){
  chomp;
  my @parsed = parse_line($dlm, 1, $_);
  
  for(my $i=0; $i<=$#parsed; $i  ){
    $parsed[$i] =~ s/$dlm//g;
  }
  
  print WH join($dlm, @parsed)."\n";
}
close(WH);
close(RH);
  •  Tags:  
  • perl
  • Related