http://www.perlmonks.org?node_id=1011398


in reply to learning perl chapter 4

Another problem with the OPed code is that it is apparently trying to do numeric comparison with the  gt string comparison operator, which does lexicographic comparison and will silently stringize its operands. The problem with this is that "2" is lexicographically greater than "10". Solution: use  < <= == != >= > <=> numeric comparison operators for numbers. See Relational Operators and Equality Operators in perlop.

>perl -wMstrict -le "sub max { my ($fred, $barney) = @_; ;; if ($fred gt $barney) { return $fred; } else { return $barney; } } ;; my $n = max(2, 10); print $n; " 2