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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

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


New User

Jul 1, 2018, 5:36 AM

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


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: (2.24 KB)

Veteran / Moderator

Jul 1, 2018, 8:07 AM

Post #2 of 5 (2912 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?

Veteran / Moderator

Jul 1, 2018, 8:10 AM

Post #3 of 5 (2911 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 module to output the csv data.

New User

Jul 1, 2018, 4:19 PM

Post #4 of 5 (2908 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 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)

Veteran / Moderator

Jul 8, 2018, 2:00 PM

Post #5 of 5 (2873 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