Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: learning perl chapter 4

by AnomalousMonk (Archbishop)
on Jan 03, 2013 at 06:36 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-03-19 09:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found