Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: learning perl chapter 4

by AnomalousMonk (Canon)
on Jan 03, 2013 at 06:36 UTC ( #1011398=note: print w/replies, xml ) Need Help??

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1011398]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2016-10-23 22:35 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (302 votes). Check out past polls.