in reply to I Keep getting the error: "my" variable $a masks earlier declaration in same scope at bigsmall.pl line 8 (#1)

$a and $b are pre-declared variables in the main package, so anytime you try to initialize the lexical variables my $a or my $b Perl warns you that you cannot access the original $a and $b in this scope.

$a and $b are used with the sort function.

Rather than using an if test to find the largest and the smallest value, you could have used the sort function:

my ($smallest, $largest) = sort {$a <=> $b} ($first, $second);
(I have replaced your $a and $b by $first and $second.)

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

  • Comment on Re: I Keep getting the error: "my" variable $a masks earlier declaration in same scope at bigsmall.pl line 8 (#1)
  • Select or Download Code