script/lottery-big-draw.pl untested

filter: Statementstmt 0.0% 0 / 69 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 106 CC 4 SCAR 23.0
CC
4
Cov
0%
custom_setup
20.0
BEGIN
2.0
BEGIN
2.0
CRAP 10.0
1 #!/usr/bin/env perl
2  
3 use 5.038;
4 use Game::Lottery;
5 use Getopt::Long::Descriptive;
6 use English;
7 use Pod::Usage;
8  
9 my ( $opt, $usage ) = describe_options(
10 'lottery-big-draw.pl %o',
11 [ 'pick|p=i', 'Pick Numbers requires the number of picks to make', ],
12 [ 'file|f=s', 'file containing picks to check (or write to)', ],
13 [
14 'winners|w=s',
15 'String containing winning picks or location of file containing winners'
16 ],
17 [
18 'ticketvalue|t=s',
19 'determine expected value of each ticket given cash value of jackpot'
20 ],
21 [
22 'game|g=s',
23 "the game: Draw, Custom, PowerBall or MegaMillions",
24 { required => 1 }
25 ],
26 [
27 'custname|cn=s',
28 'Optional Name for a custom game',
29 { default => 'Custom Game' }
30 ],
31 [ 'whiteballs|wb=i', 'For Draw or Custom game, number of white balls' ],
32 [
33 'drawwhiteballs|drawhiteballs|dwb=i',
34 'For Draw or Custom game, number of white balls to draw'
35 ],
36 [
37 'redballs|rb=i', 'For Custom game, number of red balls', { default => 0 }
38 ],
39 [
40 'drawredballs|drb=i',
41 'For Custom game, number of red balls to draw',
42 { default => 0 }
43 ],
44 [],
45 [ 'help|h', "print usage message and exit", { shortcircuit => 1 } ],
46 );
47  
48 if ( $opt->help ) {
49 print pod2usage( -verbose => 2, -message => $usage->text );
50 exit;
51 }
52  
53 my $lottery = Game::Lottery->new( game => $opt->game );
54  
55 sub custom_setup {
56 if ( $opt->game =~ /custom/i ) {
57 unless ( $opt->whiteballs && $opt->drawwhiteballs ) {
58 die "for picking a custom game whiteballs and drawwhiteballs are required\n";
59 }
60 if ( $opt->redballs ) {
61 my %balls = (
62 white => $opt->whiteballs,
63 whitecount => $opt->drawwhiteballs,
64 red => $opt->redballs,
65 redcount => $opt->drawredballs,
66 game => $opt->custname,
67 );
68 $lottery->CustomBigDrawSetup(%balls);
69 }
70 }
71 }
72  
73 if ( $opt->pick ) {
74 custom_setup();
75 my @picks = ();
76 for ( my $i = 1 ; $i <= $opt->pick ; $i++ ) {
77 printf( '%-5s', $i );
78 my $draw = do {
79 if ( $lottery->Game eq 'Draw' ) {
80 {
81 game => 'Draw', redballs => [],
82 whiteballs =>
83 $lottery->BasicDraw( $opt->whiteballs, $opt->drawwhiteballs )
84 }
85 } else {
86 $lottery->BigDraw();
87 }
88 };
89 # $opt->drawredballs
90 # ? $lottery->BigDraw()
91 # : {
92 # game => $lottery->Game,
93 # whiteballs =>
94 # $lottery->BasicDraw( $opt->whiteballs, $opt->drawwhiteballs ),
95 # redballs => [],
96 # };
97 say
98 qq/${\ $draw->{game} } | ${\ do { join ' ', $draw->{whiteballs}->@* } } | ${\ do { join ' ', $draw->{redballs}->@* } }/;
99 push @picks, $draw;
100 }
101 if ( $opt->file ) {
102 $lottery->SavePicks( $opt->file, \@picks );
103 }
104 }
105 elsif ( $opt->ticketvalue ) {
106 my $jp = $opt->ticketvalue;
107 my $tv = $lottery->TicketValue( $opt->ticketvalue );
108 if ( $jp < 10**6 ) { $jp = "${jp} Million Dollars" }
109 else { $jp = "${jp} Dollars" }
110 say
111 "A ${\ $lottery->Game } ticket with a Jackpot of ${jp} is worth: \$${tv}";
112 }
113 elsif ( $opt->winners ) {
114 my $winf = $opt->winners;
115 if ( $winf !~ /[A-Za-z]/ ) {
116 open(
117 my $tmpfile,
118 '>',
119 '/tmp/lottery.tmp'
120 || die "unable to save winners to temporary file $!\n"
121 );
122 say $tmpfile $winf;
123 close $tmpfile;
124 $winf = '/tmp/lottery.tmp';
125 }
126 my @results = $lottery->CheckPicks( $winf, $opt->file );
127 local $LIST_SEPARATOR = "\n";
128 say "@results";
129 }
130  
131 =pod
132  
133 =head1 NAME
134  
135 lottery-big-drawl.pl
136  
137 =head1 VERSION
138  
139 version 1.04
140  
141 =head1 About
142  
143 This script will display information about lottery games, pick numbers to play, and check
144 numbers from a file.
145  
146 =head1 Usage
147  
148 # pick 5 Megamillions games output data to mypicks.ticket
149 # if no file picks display to STDOUT only.
150 lottery-big-draw.pl --pick 5 --game MegaMillions --file mypicks.ticket
151  
152 # check winners for file mypicks.ticket
153 lottery-big-draw.pl --winners "01 02 03 04 05 [06]" --file mypicks.ticket
154 lottery-big-draw.pl -w winners.ticket -f mypicks.ticket
155  
156 # estimate expected value of a PowerBall ticket given the cash jackpot
157 # value of 1.6 bln (value can be given in millions or dollars)
158 lottery-big-draw.pl -g PowerBall -t 1600
159  
160 # custom games can be created with the custom type and options.
161  
162 lottery-big-draw.pl -g Custom --wb 50 --dwb 5 --rb 30 --drb 1 -p 1 -f $filepath \
163 --custname "My Custom Lottery"
164  
165 # Basic draw games use only the whiteballs.
166  
167 lottery-big-draw.pl -g draw --wb 50 --dwb 5 -p 10
168  
169 =head1 Additional Documentation
170  
171 lottery-big-drawl.pl us bundled with Game::Lottery, additional information
172 can be obtained with the command C<perldoc Game::Lottery>. The file format
173 is detailed there.
174  
175 =head1 Command Line Options
176  
177 lottery-big-draw.pl [-fghptw] [long options...]
178  
179 --pick INT (or -p) Pick Numbers requires the number of picks
180 to make
181 --file STR (or -f) file containing picks to check (or write to)
182 --winners STR (or -w) String containing winning picks or
183 location of file containing winners
184 --ticketvalue STR (or -t) determine expected value of each ticket
185 given cash value of jackpot
186 --game STR (or -g) the game: Draw, Custom, PowerBall or
187 MegaMillions
188 --custname STR Optional Name for a custom game
189 aka --cn
190 --whiteballs INT For Draw or Custom game, number of white balls
191 aka --wb
192 --drawwhiteballs INT For Draw or Custom game, number of white
193 balls to draw
194 aka --drawhiteballs, --dwb
195 --redballs INT For Custom game, number of red balls
196 aka --rb
197 --drawredballs INT For Custom game, number of red balls to draw
198 aka --drb
199  
200 --help (or -h) print usage message and exit
201  
202 =cut