Next | 4.0 Caveats for Perl programmers | Prev |
Caveat #1. Numbers and strings are not interchangable! Perl code:
print "2" + "3.1415926"; print 2 . 2;
Corresponding Ruby code:
print "2".to_i + "3.1415926".to_f print 2.to_s + 2.to_s
Caveat #2. Zero and empty string are true values! Perl code:
print $value if $value; print $value if defined($value); sort { uc($a) <=> uc($b) || $a <=> $b } @arr;
Corresponding Ruby code:
print value if value && !value.eql?(0) && !value.eql?("") print value if value # or: if defined?(value) arr.sort { |a,b| (a.upcase <=> b.upcase).nonzero? || a <=> b }
Next | Ruby for Perl programmers | Prev |