From jacobson@math-cs.cns.uni.edu Tue Jul 16 17:09:42 2002 Date: Mon, 15 Jul 2002 16:25:24 -0500 (CDT) From: Mark Jacobson To: 810-088-06@uni.edu Subject: Making the external java file with HTML in it.... Try out these FOUR lines of PERL code. They illustrate the substitution operator =~ s/toFind/toReplaceWith/GlobalOption used to g as in globally find all occurrences of " in the data and replace them with \" (the two characters backslash and double quote). $string = "This is a string containing \"Double Quotes\" for now."; print "\n$string\n"; $string =~ s/"/\\"/g; print "\n$string\n"; FOR A SIMPLER EXAMPLE, TRY THIS ONE. perl -e '$str="Hello Molly and Sally"; $str =~ s/l/WW/g; print "$str\n";' HeWWWWo MoWWWWy and SaWWWWy <---- OUTPUT with l's replaced by WW -------- makeJavaScript.pl ------------------------------------------- open (FILE, "writeToForm.html"); open (OUTFILE, ">testing.js"); $doubleQuote = "\""; while () { chomp; $_ =~ s/"/\\"/g; $_ = "$doubleQuote $_ \\n$doubleQuote +\n"; print OUTFILE $_; } close FILE; close OUTFILE; --------------------------------------------------------------------------- I will show the output in the hands-on class on Tuesday. If you want to see what the funny results of the JavaScript are so far, check out the URL: http://www.cns.uni.edu/~jacobson/js/writeToForm.html and click the 2nd button first, then click either button as many times as you wish. You will see repeated pages. Mark