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: Perl Programming Help: Intermediate: Write the data by preserving quote characters: Edit Log

New User

Dec 8, 2014, 3:12 PM

Views: 6159
Write the data by preserving quote characters


I have my source data coming from webservice call. The data is comma delimited with quote characters. I would like to write the output to a text file by preserving the quote characters.

my input of webservice (from browser):
"$2,355",2355,"$2,355",Approved,Approved,Approved,Approve,davecass,"awadhwa, azin",,,2014-10-28,0,2014-10-28,prad

output to be the same
"$2,355",2355,"$2,355",Approved,Approved,Approved,Approve,davecass,"awadhwa, azin",,,2014-10-28,0,2014-10-28,dblee

$data has the output of webservice

              my $csv = Text::CSV->new ({ 
binary => 1, # Allow special character. Always set this
auto_diag => 1, # Report irregularities immediately
sep_char => ',', #Separatrp
open (my $fh1,"<:encoding(utf8)",\$data) or die "$!";
my $firstLine = 1;
while (my $row = $csv->getline($fh1)) {
$firstLine = 0;
open(my $fh2,'>>',$filename) or die "Could not open file '$filename' $!";
print $fh2 "$row->[0],$row->[1],$row->[2],$row->[3],$row->[4],$row->[5],$row->[13],$row->[16],$row->[17],$row->[18],$row->[19],$row->[20],$row->[21],$row->[22],$row->[23],$row->[24],$row->[26],$row->[29],$row->[30],$row->[31]\n";
close $fh2;
close $fh1;

This is not preserving quotes. How to preserve the quotes

(This post was edited by FishMonger on Dec 9, 2014, 10:49 AM)

Edit Log:
Post edited by FishMonger (Veteran) on Dec 9, 2014, 10:49 AM: Added code tags

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

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