| 1 | #!/usr/bin/env perl | ||
| 2 | |||
| 3 | use 5.038; | ||
| 4 | use Game::Lottery; | ||
| 5 | use Getopt::Long::Descriptive; | ||
| 6 | use English; | ||
| 7 | |||
| 8 | my $help = q/ | ||
| 9 | Pick, Check, or get a ticket value. | ||
| 10 | |||
| 11 | # pick 5 Megamillions games output data to mypicks.ticket | ||
| 12 | # if no file picks display to STDOUT only. | ||
| 13 | lottery-big-draw.pl --pick 5 --game MegaMillions --file mypicks.ticket | ||
| 14 | |||
| 15 | # check winners for file mypicks.ticket | ||
| 16 | lottery-big-draw.pl --winners "01 02 03 04 05 [06]" --file mypicks.ticket | ||
| 17 | lottery-big-draw.pl -w winners.ticket -f mypicks.ticket | ||
| 18 | |||
| 19 | # estimate expected value of a PowerBall ticket given the cash jackpot | ||
| 20 | # value of 1.6 bln (value can be given in millions or dollars) | ||
| 21 | lottery-big-draw.pl -g PowerBall -t 1600 | ||
| 22 | |||
| 23 | /; | ||
| 24 | |||
| 25 | my ($opt, $usage) = describe_options( | ||
| 26 | 'lottery-big-draw.pl %o', | ||
| 27 | [ 'pick|p=i', 'Pick Numbers requires the number of picks to make', ], | ||
| 28 | [ 'file|f=s', "file containing picks to check (or write to)", ], | ||
| 29 | [ 'winners|w=s', "String containing winning picks or location of file containing winners" ], | ||
| 30 | [ 'ticketvalue|t=s', 'determine expected value of each ticket given cash value of jackpot'], | ||
| 31 | [ 'game|g=s', "the game: PowerBall or MegaMillions", { required => 1 } ], | ||
| 32 | [], | ||
| 33 | [ 'help|h', "print usage message and exit", { shortcircuit => 1 } ], | ||
| 34 | ); | ||
| 35 | |||
| 36 | if ($opt->help) { | ||
| 37 | print( $help, $usage->text ); | ||
| 38 | exit; | ||
| 39 | } | ||
| 40 | |||
| 41 | my $lottery = Game::Lottery->new( game => $opt->game ); | ||
| 42 | |||
| 43 | if ( $opt->pick ) { | ||
| 44 | my @picks = (); | ||
| 45 | for ( my $i = 1; $i <= $opt->pick; $i++) { | ||
| 46 | print sprintf('%-5s', $i); | ||
| 47 | my $draw = $lottery->BigDraw(); | ||
| 48 | say | ||
| 49 | qq/${\ $draw->{game} } | ${\ do { join ' ', $draw->{whiteballs}->@* } } | ${\ do { join ' ', $draw->{redballs}->@* } }/; | ||
| 50 | push @picks, $draw; | ||
| 51 | } | ||
| 52 | if ( $opt->file ) { | ||
| 53 | $lottery->SavePicks( $opt->file, \@picks); | ||
| 54 | } | ||
| 55 | } elsif ( $opt->ticketvalue ) { | ||
| 56 | my $jp = $opt->ticketvalue; | ||
| 57 | my $tv = $lottery->TicketValue( $opt->ticketvalue ); | ||
| 58 | if ( $jp < 10**6 ) { $jp ="${jp} Million Dollars"} | ||
| 59 | else { $jp = "${jp} Dollars"} | ||
| 60 | say "A ${\ $opt->game } ticket with a Jackpot of ${jp} is worth: \$${tv}"; | ||
| 61 | } elsif ( $opt->winners ) { | ||
| 62 | my $winf = $opt->winners ; | ||
| 63 | if ( $winf !~ /[A-Za-z]/) { | ||
| 64 | open (my $tmpfile, '>', '/tmp/lottery.tmp' || | ||
| 65 | die "unable to save winners to temporary file $!\n"); | ||
| 66 | say $tmpfile $winf ; | ||
| 67 | close $tmpfile; | ||
| 68 | $winf = '/tmp/lottery.tmp'; | ||
| 69 | } | ||
| 70 | my @results = $lottery->CheckPicks ( $winf, $opt->file ); | ||
| 71 | local $LIST_SEPARATOR = "\n"; | ||
| 72 | say "@results"; | ||
| 73 | } | ||
| 74 | |||
| 75 | =pod | ||
| 76 | |||
| 77 | =head1 NAME | ||
| 78 | |||
| 79 | lottery-big-drawl.pl | ||
| 80 | |||
| 81 | =head1 VERSION | ||
| 82 | |||
| 83 | version 1.03 | ||
| 84 | |||
| 85 | =head1 About | ||
| 86 | |||
| 87 | This script will display information about lottery games, pick numbers to play, and check numbers from a file. | ||
| 88 | |||
| 89 | =head1 Usage | ||
| 90 | |||
| 91 | Usage instructions can be obtained from help. Details on the Module Game::Lottery, including the file format for tickets, can be obtained via the perldoc command. | ||
| 92 | |||
| 93 | lottery-big-draw.pl --help | ||
| 94 | perldoc Game::Lottery | ||
| 95 | |||
| 96 | =cut |