Skip to content

Commit

Permalink
Slight reordering to simplify code.
Browse files Browse the repository at this point in the history
  • Loading branch information
davorg committed May 26, 2017
1 parent d7bb2e3 commit dd9277f
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions Lotto.pm
Expand Up @@ -43,6 +43,19 @@ sub parse_args {
my ($type, $count) = qw[lotto 1];
my @errs;

return ($type, $count) unless @_;

if (@_ == 1) {
if ($_[0] =~ /^\d+$/) {
$count = shift;
} elsif (exists $config->{$_[0]}) {
$type = shift;
} else {
push @errs, qq["$_[0]" doesn't look like a positive integer or a ] .
qq[type of lottery];
}
}

if (@_ == 2) {
($count, $type) = (undef, undef);
my ($first, $second) = (shift, shift);
Expand All @@ -62,17 +75,6 @@ sub parse_args {
}
}

if (@_ == 1) {
if ($_[0] =~ /^\d+$/) {
$count = shift;
} elsif (exists $config->{$_[0]}) {
$type = shift;
} else {
push @errs, qq["$_[0]" doesn't look like a positive integer or a ] .
qq[type of lottery];
}
}

if (@_ || @errs) {
push @errs, 'Usage: lotto [' .
join('|', keys %$config) .
Expand Down

0 comments on commit dd9277f

Please sign in to comment.