| 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 | push @picks, $lottery->BigDraw(); | ||
| 48 | } | ||
| 49 | if ( $opt->file ) { | ||
| 50 | $lottery->SavePicks( $opt->file, \@picks); | ||
| 51 | } | ||
| 52 | } elsif ( $opt->ticketvalue ) { | ||
| 53 | my $jp = $opt->ticketvalue; | ||
| 54 | my $tv = $lottery->TicketValue( $opt->ticketvalue ); | ||
| 55 | if ( $jp < 10**6 ) { $jp ="${jp} Million Dollars"} | ||
| 56 | else { $jp = "${jp} Dollars"} | ||
| 57 | say "A ${\ $opt->game } ticket with a Jackpot of ${jp} is worth: \$${tv}"; | ||
| 58 | } elsif ( $opt->winners ) { | ||
| 59 | my $winf = $opt->winners ; | ||
| 60 | if ( $winf !~ /[A-Za-z]/) { | ||
| 61 | open (my $tmpfile, '>', '/tmp/lottery.tmp' || | ||
| 62 | die "unable to save winners to temporary file $!\n"); | ||
| 63 | say $tmpfile $winf ; | ||
| 64 | close $tmpfile; | ||
| 65 | $winf = '/tmp/lottery.tmp'; | ||
| 66 | } | ||
| 67 | my @results = $lottery->CheckPicks ( $winf, $opt->file ); | ||
| 68 | local $LIST_SEPARATOR = "\n"; | ||
| 69 | say "@results"; | ||
| 70 | } | ||
| 71 | |||
| 72 | =pod | ||
| 73 | |||
| 74 | =head1 NAME | ||
| 75 | |||
| 76 | lottery-big-drawl.pl | ||
| 77 | |||
| 78 | =head1 VERSION | ||
| 79 | |||
| 80 | version 1.02 | ||
| 81 | |||
| 82 | =head1 About | ||
| 83 | |||
| 84 | This script will display information about lottery games, pick numbers to play, and check numbers from a file. | ||
| 85 | |||
| 86 | =head1 Usage | ||
| 87 | |||
| 88 | 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. | ||
| 89 | |||
| 90 | lottery-big-draw.pl --help | ||
| 91 | perldoc Game::Lottery | ||
| 92 | |||
| 93 | =cut |