html - Delete one character at End of File in PERL -
so have encountered problem while programming perl. utilize foreach loop info out of hash, has loop through it.
the code:
foreach $title (keys %filtersprinthash) { $opensp = $filtersprinthash{$title}{opensp}; $estsp = $filtersprinthash{$title}{estsp}; $line = "'$title':{'opensp' : $opensp, 'estsp' : $estsp}\n"; print $outfile "$line\n"; }
the thing is, creating seperate file perl's writting file expression, jsonp text (later used html).
back problem:
as jsonp requires comma's "," after every line not lastly one, had set comma @ end of line, however when lastly line comes in, have remove comma.
i have tried chop function, not sure set it, since if set @ end of foreach, chop comma in $line, wont chop in new file created.
i have tried while (<>) statement, no success.
any ideas appreaciated.
br
using json
module far less error prone; no need reinvent wheel
use json; print $outfile encode_json(\%filtersprinthash), "\n";
html perl jsonp
No comments:
Post a Comment