
leptogenesis
Novice
Jul 16, 2009, 12:06 PM
Post #10 of 12
(1019 views)
|
|
Re: [FishMonger] escape strings for javascript?
[In reply to]
|
Can't Post
|
|
I've tried CPAN...no luck, although there were a couple of modules (e.g. Encode::Escape) which look like they might do close to the right thing. I can't figure out exactly what Encode::Escape actually does. Anyway, you asked for it...I've attached an actual file that I need to embed in javascript. They're characters and bounding boxes for an OCR translation of a document, and will eventually allow people to review the OCR program's translations over mechanical turk. Unfortunately, because of mechanical turk's restrictions, I need to have the entire file in a single variable, since I need to be able to tell mechanical turk beforehand how many variables I have. The perl code that actually creates the .csv files for mechanical turk is below, with the code for finding the prop_info files stripped:
my $csv = Text::CSV->new({binary => 1}); ... open PROPINF, "<", "$file/$pagefile/prop_info.txt"; my @propinfolines = <PROPINF>; for(my $i=0; $i<$#propinfolines+1; $i++){ $propinfolines[$i]=~s/\\/\\\\/g; $propinfolines[$i]=~s/\'/\\u0027/g; $propinfolines[$i]=~s/\"/\\\"/g; $propinfolines[$i]=~s/\t/\\t/g; $propinfolines[$i]=~s/\n/\\n/g; $propinfolines[$i]=~s/\r/\\r/g; } my $propinfo = join('',@propinfolines); if(! $csv->combine($docname,$docpage,$propinfo)){ print "can't combine"; exit } my $str = $csv->string(); chomp $str; print FILE $str; Let me know if any more details would be useful.
|