CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: General Discussions: General Questions:
Perl script not handeling LR and quotes

 



gudgeong
New User

Jul 1, 2018, 5:36 AM

Post #1 of 5 (485 views)
Perl script not handeling LR and quotes Can't Post

Hi,

I use a perl script to convert a firewall XML file to CSV but in some of the description entries there are LR and quotes (") that mess up the output when exporting it to a csv file

I wonder if someone might be able to explain this function and how I might be able to tweak it so that the output does not corrupt when LR and quotes(") are found in the specific XML field.

Here is an example of the problem part of the source XML file the script runs on. not the hard returns and the " in the <description> section.

****************************************************
<description>"Allow connection from Internal Servers
to External Servers
contact sopmeone for help"</description>
****************************************************

There are hard returns and quotes which breakup the output and forces the output to go to a separate line when piping output at the command line to a xxx.csv file. There are a number of other fields in the source XML files I use with this perl script but I think the above would like point to the problem for anyone who know anything about perl(Which is a hell of a lot more than me ;) )

I have attached the perl script to the forum message as well.
Attachments: extractconf.pl (2.24 KB)


FishMonger
Veteran / Moderator

Jul 1, 2018, 8:07 AM

Post #2 of 5 (482 views)
Re: [gudgeong] Perl script not handeling LR and quotes [In reply to] Can't Post

Quotes in csv fields are fine, but if you don't want them, you could use a regex to strip them out.

Likewise, have you tried applying a regex to the affected fields to replace the returns with a space?


FishMonger
Veteran / Moderator

Jul 1, 2018, 8:10 AM

Post #3 of 5 (481 views)
Re: [gudgeong] Perl script not handeling LR and quotes [In reply to] Can't Post

You may also want to look at using the https://metacpan.org/pod/Text::CSV module to output the csv data.


gudgeong
New User

Jul 1, 2018, 4:19 PM

Post #4 of 5 (478 views)
Re: [FishMonger] Perl script not handeling LR and quotes [In reply to] Can't Post

Thanks for the advice

I will look at the Regex option in my editor to remove the offending characters prior to running the script.

Just for more detail I have provided a sanitised snippet of the output I get when the script hits these quotes or LR's

Oh and I didn't mention that the errors I get from the script come up as :

***************************************
Wide character in print at extractconf.pl line 63.
***************************************

I think this is only related to stdout but thought i would mention

This might be related to the issue or not since I have manually gone into the file and removed all the quotes and LR's and the output looks ok but I still see these errors..

Cheers and thanks again for the pointers.


(This post was edited by gudgeong on Jul 1, 2018, 4:41 PM)
Attachments: sample.csv (0.53 KB)


Laurent_R
Veteran / Moderator

Jul 8, 2018, 2:00 PM

Post #5 of 5 (443 views)
Re: [gudgeong] Perl script not handeling LR and quotes [In reply to] Can't Post

The "Wide character in print ..." error has to do with character encoding (Unicode, UTF-8 vs ISO-Latin-whatever, and so on) and it tends to be a somewhat complicated can of worms.

Basically, you need to tell Perl how to decode the input and how to encode the output.

Please show us how you open your input files and your output files to give us a chance to help you.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives