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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|