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



pradeep1982
New User

Dec 9, 2014, 1:58 PM


Views: 5926
Re: [FishMonger] Write the data by preserving quote characters

This is my new code

Code
use Getopt::Long; 
use File::Copy;
use Text::CSV;

my $filename = '/mydir/file.txt';
my $filename2 = '/mydir/file_formatted.csv';

unlink $filename;

for (my $i=1;$i<=2;$i++)
{
$WS_URL = "www.adesfhr.com/wpi.php?cmd=dsd&PageNumber=$i&pageSize=10&responseType=csv";
my $resp=$SSO->get($WS_URL);
my $data = $resp->content();
if ($data)
{
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 "$!";
open(my $fh2,'>>',$filename) or die "Could not open file '$filename' $!";
my $firstLine = 1;
while (my @row = $csv->getline($fh1))
{
if($firstLine)
{
$firstLine = 0;
}
else{
# print qq("$row->[0]|$row->[4]\n)";
my @newrow=splice(@row,0,3);
print "@newrow\n";
$csv->print($fh2,$newrow[0]);
}
}
close $fh2;
close $fh1;
}
else
{
last ;
}
}


This is printing all hash values
ARRAY(0xa03945c)
ARRAY(0xa039594)
ARRAY(0xa03969c)
ARRAY(0xa0396a8)
ARRAY(0xa039678)
ARRAY(0xa039774)
ARRAY(0xa0394d4)
ARRAY(0xa039630)
ARRAY(0xa001160)
ARRAY(0xa0393c0)
ARRAY(0xa0049fc)
ARRAY(0xa0a2aa8)
ARRAY(0xa03957c)
ARRAY(0x9fdbfb4)
ARRAY(0x9fe7ea0)
ARRAY(0xa0049fc)
ARRAY(0x9fe7ce4)
ARRAY(0xa04e4c8)
ARRAY(0xa0908c8)
ARRAY(0xa03957c)

and writing nothing to file

Please suggest


(This post was edited by FishMonger on Dec 9, 2014, 2:08 PM)


Edit Log:
Post edited by FishMonger (Veteran) on Dec 9, 2014, 2:08 PM: 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