JavaScript version of the Perl/PHP performance test

Using the Rhino compiler… sorry no benchmark numbers, but just as a placeholder. To pick a nit, wanted to do first[m[1]] += parseInt(m[3]) but that yeilded a NaN since first[m[1]] was undefined... You would think that JavaScript would make undefined == 0.

 1fd = java.io.BufferedReader(java.io.FileReader('p.test'))
 2
 3mre = /^__MULTI_TOKEN__\s+(\S+)\s+(.*)\t?\s*(\d+)\s*$/;
 4sre = /^__SINGLE_TOKEN__\s+(\S+)\s*\t?\s*(\d+)\s*$/;
 5
 6ofd = java.io.PrintWriter(java.io.FileWriter('full.txt'));
 7first = {}
 8
 9while (line = fd.readLine()) {
10    if (m = line.match(mre)) {
11        first[m[1]] = (first[m[1]] ? first[m[1]] : 0) + parseInt(m[3]);
12        ofd.println(m[1] + " " + m[2] + "\t" + m[3]);
13    } else if (m = line.match(sre)) {
14        first[m[1]] = (first[m[1]] ? first[m[1]] : 0) + parseInt(m[2]);
15    } else {
16        print("Unknown: " + line);
17    }
18}
19
20ofd.close()
21
22ofd = java.io.PrintWriter(java.io.FileWriter('first.txt'));
23//  Sigh... rhino needs an update...
24//   first.forEach(function(e, i, a) { ofd.println(i + "\t" + e); });
25for (key in first) {
26    ofd.println(key + "\t" + first[key]);
27}
28ofd.close()

This is all based on the PHP/Perl/Python performance code.