Here is a little program I wrote that will download
the winning supper lottery numbers and show you which
tickets have winning numbers.
I wrote this code to see how the LWP::Simple module works and learn a little bit more about pattern matching.
I really suck at pattern matching so I might have not done it the best way, but it works.
Sample Lottery data file: Last number is mega number
4::33::8::7::18::3
5::6::9::14::10::1
9::32::15::3::1::2
6::32::9::15::24::9
zzLOTTOz: check your supper lotto tickets
#!/usr/bin/perl -Tw
# zzlottoz
# check and see if you win the lottery.
use LWP::Simple;
my $url = "http://209.210.49.50/winningnumbers.asp";
my $lotto_file = shift || "lotto.txt";
my @numbers = ();
my @winners = ();
my $mega = "";
my %lotto;
open LOTTO, $lotto_file or die "Couldn't open lotto data file: $!\n.";
while (<LOTTO>){
my @data = split /::/;
push @numbers, [ @data ];
}
close LOTTO or warn "Error while closing lotto data file: $!\n.";
my $web = get ($url);
die "Unable to download lottery numbers.\n" unless (defined($web));
(@winners) = $web =~ /Super Lotto Plus Winning Numbers:\s+(\d{1,2})\s+
+(\d{1,2})\s+(\d{1,2})\s+(\d{1,2})\s+(\d{1,2})\s+Mega\s+(\d{1,2})/s;
$mega = pop @winners;
die "Error parsing lotto numbers!\n" unless ((@winners) && (defined($m
+ega)));
foreach my $num (@winners){
$lotto{$num}= 1;
}
print "\n LOTTO RESULTS: @winners MEGA: $mega\n\n";
print " N U M B E R S MEGA\n";
foreach my $ticket (@numbers){
foreach my $num ( (@$ticket[0..4]) ){
($lotto{$num}) ? printf(" [%2u] ",$num) : printf (" %2u ",$n
+um);
}
($$ticket[5] == $mega) ? printf " [%2u] ",$mega : printf " %2u "
+,$$ticket[5];
print "\n";
}
Im really starting to like perl! Perl kicks butt!
zzSPECTREz