Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

California Super Lotto Checker

by zzspectrez (Hermit)
on Nov 19, 2000 at 15:43 UTC ( [id://42415]=CUFP: print w/replies, xml ) Need Help??

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

Replies are listed 'Best First'.
Re: California Super Lotto Checker
by blogan (Monk) on Nov 20, 2000 at 02:21 UTC
    I would probably put a little more error checking into the extracting the numbers from the web page (make sure they're the proper size, etc), because that would really suck if they changed the HTML on that page and:

    What!?!? Those were the numbers for yesterday!?!? My perl script said I lost and I tore up the ticket. Arg!!!

    Which kind of makes you think, to what extent would you trust a computer to do something for you? Would you let a program analyze the market and trade your stocks for you?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://42415]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-12-14 17:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which IDE have you been most impressed by?













    Results (70 votes). Check out past polls.