code_junkie

What does “0 but true” mean in Perl?

Nov 11th, 2011
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. $ perl -wle 'print "0 but true" + 3'
  2. 3
  3. $ perl -wle 'print "0 but crazy" + 3'
  4. Argument "0 but crazy" isn't numeric in addition (+) at -e line 1.
  5. 3
  6.  
  7. while($c = characters_in_line($file)){
  8. ...
  9. };
  10.  
  11. $ strings /usr/lib/perl5/5.10.0/linux/CORE/libperl.so | grep -i true
  12. Perl_sv_true
  13. %-p did not return a true value
  14. 0 but true
  15. 0 but true
  16.  
  17. if(x)
  18.  
  19. for x: yields:
  20. 1 -> true
  21. 0 -> false
  22. -1 -> true
  23. "true" -> true
  24. true -> true
  25. "false" -> true
  26. false -> false # notice the quotes
  27. "0 but true" ->true #
  28. int("0 but true") ->false
  29.  
  30. sub find_x()
  31.  
  32. if($x = find_x)
  33. {
  34. print int($x) . "n";
  35. }
Add Comment
Please, Sign In to add comment