http://www.perlmonks.org?node_id=1175431

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

Dear All, Firstly, just to let you know I know nothing of PERL but I've inherited a small script which essentially converts an CSV file into a XML file. This XML file is then parsed by our VoIP phones as a phone directory. We have a new brand of phones which parses double quotes from the XML file where others do not. Below is the code that is generating the XML:
#!/usr/bin/perl -w #fn - First Name #ct - Extension #use strict ; #use warnings ; #Name if the File that contains the User Direcotry Data open (FILE, 'phonelist.csv') || die("Could not open the input file dir +ectory.csv!\n"); #create if not yet created and/or overwrite existing directory-0000000 +00000.xml open (OUTPUTFILE, ">000000000000-directory.xml") || die("Could not ope +n/create the output file directory-000000000000.xml!\n"); #below section contains the standard [general] header of the sip.conf print OUTPUTFILE "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone= +\"yes\"?>\n"; print OUTPUTFILE "<directory>\n"; print OUTPUTFILE "\t<item_list>\n"; while (<FILE>) { chomp; ################################################################### #we are splitting the comma seperated values into the single Items# #add additional $columnX to accomodate further entries# ################################################################### ($column1,$column2,) = split(','); print OUTPUTFILE "\t\t<item>\n"; print OUTPUTFILE "\t\t\t<fn>$column1</fn>\n"; print OUTPUTFILE "\t\t\t<ct>$column2</ct>\n"; print OUTPUTFILE "\t\t</item>\n"; } print OUTPUTFILE "\t</item_list>\n"; print OUTPUTFILE "</directory>\n"; #close the csv example file close (FILE); #close the modified sip.conf file close (OUTPUTFILE); exit;
The source CSV file has quotes around the string in column 1 which I cannot change. I need a way for the above script to remove or ignore double quotes.. even snipping a character from the beginning and end would do. Any help appreciated. Cheers, Jake

Replies are listed 'Best First'.
Re: Remove Double Quotes from XML Output
by toolic (Bishop) on Nov 07, 2016 at 13:31 UTC
    The following removes all double quotes from the string stored in the $column1 variable using the substitution operator:
    ($column1,$column2,) = split(','); $column1 =~ s/"//g;

    If that does not work for you, then you should show several examples of strings you are working with.

      That worked perfectly - thank you very much.