Skip to content

Commit 77ce1d4

Browse files
authored
cal: deal with warnings (#805)
* When temporarily enabling warnings.pm I noticed two patterns which generated a warning * In get_year(), regex check was done too late after the variable has been treated as a number * In print_year()/print_year_jd() the month lists being combined might have a less elements; explicitly treat those as empty string
1 parent 8934637 commit 77ce1d4

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

bin/cal

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ sub print_year_jd {
8080
my @m1 = fmt_month($cal::year, $mon[1], 0);
8181

8282
foreach my $i (0 .. 7) {
83+
$m0[$i] = '' unless defined $m0[$i];
84+
$m1[$i] = '' unless defined $m1[$i];
8385
printf "%-${w}s %-${w}s\n", $m0[$i], $m1[$i];
8486
}
8587
}
@@ -95,6 +97,9 @@ sub print_year {
9597
my @m2 = fmt_month($cal::year, $mon[2], 0);
9698

9799
foreach my $i (0 .. 7) {
100+
$m0[$i] = '' unless defined $m0[$i];
101+
$m1[$i] = '' unless defined $m1[$i];
102+
$m2[$i] = '' unless defined $m2[$i];
98103
printf "%-${w}s %-${w}s %-${w}s\n", $m0[$i], $m1[$i], $m2[$i];
99104
}
100105
}
@@ -249,7 +254,7 @@ sub get_month {
249254

250255
sub get_year {
251256
my( $year ) = @_;
252-
if( $year < 1 || $year > 9999 || $year !~ /^\d+$/o ) {
257+
if ($year !~ m/\A[0-9]+\z/ || $year < 1 || $year > 9999) {
253258
print "INVALID YEAR ENTERED.\n";
254259
display_help();
255260
}

0 commit comments

Comments
 (0)