Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: learning perl chapter 4

by AnomalousMonk (Monsignor)
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


Comment on Re: learning perl chapter 4
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (17)
As of 2014-08-21 13:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (135 votes), past polls