#!/usr/bin/perl # # Generates draws.js from SuperLottoPlus.txt (download at calottery.com) # The SuperLOTTO Plus jackpot starts at $7 million, and has reached a record $193 million because the jackpot grows each time there is no winner. To win, all you have to do is pick five numbers from 1 to 47 and one MEGA number from 1 to 27 and match them to the numbers drawn by the Lottery. Winning numbers are drawn every Wednesday and Saturday at 7:57 PM. # Sample SuperLottoPlus.txt contents: # draw_nbr draw_date draw_result1 draw_result2 draw_result3 draw_result4 draw_result5 draw_resultM bonus_result01 bonus_result02 bonus_result03 bonus_result04 bonus_result05 bonus_result06 bonus_result07 bonus_result08 bonus_result09 bonus_result10 bonus_result11 bonus_result12 bonus_result13 bonus_result14 bonus_result15 # -------- ---------- ------------ ------------ ------------ ------------ ------------ ------------ -------------- -------------- -------------- -------------- -------------- -------------- -------------- -------------- -------------- -------------- -------------- -------------- -------------- -------------- -------------- # # 2175 02-06-2008 2 20 30 31 46 27 # 2130 09-01-2007 5 14 22 39 47 10 27879492 27231801 28373305 29070040 29036665 29206703 27033376 27938022 28987480 27319069 $date = $ARGV[0]; # Remove old file first. `rm -f ./draws-*.js`; $outfile = "./draws-$date.js"; open (IN, "./SuperLottoPlus.txt"); open (OUT, ">$outfile"); print OUT "YAHOO.example.draws = [\n"; $headerProcessed = 0; $widthsProcessed = 0; $firstRowProcessed = 0; while () { chomp; s/\n//g; s/\r//g; next if !$_; if (!$headerProcessed) { $headerProcessed = 1; @headers = split /\s+/; #print STDERR "read " . $#headers . " headers\n"; next; } if (!$widthsProcessed) { $widthsProcessed = 1; @widths = split /\s+/; for ($ii = 0; $ii <= $#widths; $ii++) { $widths[$ii] = length $widths[$ii]; } #print STDERR "read " . $#widths . " widths\n"; next; } if ($firstRowProcessed) { print OUT ",\n"; } else { $firstRowProcessed = 1; } $count = 0; print OUT "{ "; for ($ii = 0; $ii <= $#headers; $ii++) { print OUT ", " if $ii; $isDate = $ii == 1; $value = substr($_, $count, $widths[$ii]); $value *= 1 if !$isDate; print OUT $headers[$ii] . ": " . ($isDate ? "\"" : "") . $value . ($isDate ? "\"" : ""); $count += $widths[$ii]; $count++; # skip widths divider } print OUT " }"; } print OUT "\n];\n"; close (IN); close (OUT); #print STDERR "Done.\n";