Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. if (/D/) { print "has nondigitsn" }
  2. if (/^d+$/) { print "is a whole numbern" }
  3. if (/^-?d+$/) { print "is an integern" }
  4. if (/^[+-]?d+$/) { print "is a +/- integern" }
  5. if (/^-?d+.?d*$/) { print "is a real numbern" }
  6. if (/^-?(?:d+(?:.d*)?&.d+)$/) { print "is a decimal numbern" }
  7. if (/^([+-]?)(?=d&.d)d*(.d*)?([Ee]([+-]?d+))?$/)
  8. { print "a C floatn" }
  9.  
  10. sub is_int {
  11. $str = $_[0];
  12. #trim whitespace both sides
  13. $str =~ s/^s+|s+$//g;
  14.  
  15. #flatten to string and match dash or plus and one or more digits
  16. if ($str =~ /^(-|+)?d+?$/) {
  17. print "yes " . $_[0] . "n";
  18. }
  19. else{
  20. print "no " . $_[0] . "n";
  21. }
  22. }
  23. is_int(-12345678901234); #yes
  24. is_int(-1); #yes
  25. is_int(23.); #yes
  26. is_int(-23.); #yes
  27. is_int(0); #yes
  28. is_int(+1); #yes
  29. is_int(12345678901234); #yes
  30. is_int("t23"); #yes
  31. is_int("23t"); #yes
  32. is_int("08"); #yes
  33. is_int("-12345678901234"); #yes
  34. is_int("-1"); #yes
  35. is_int("0"); #yes
  36. is_int("+1"); #yes
  37. is_int("123456789012345"); #yes
  38. is_int("-"); #no
  39. is_int("+"); #no
  40. is_int("yadz"); #no
  41. is_int(""); #no
  42. is_int(undef); #no
  43. is_int("- 5"); #no
  44. is_int("+ -5"); #no
  45. is_int("23.1234"); #no
  46. is_int("23."); #no
  47. is_int("--1"); #no
  48. is_int("++1"); #no
  49. is_int(" 23.5 "); #no
  50. is_int(".5"); #no
  51. is_int(",5"); #no
  52. is_int("%5"); #no
  53. is_int("5%"); #no
  54.  
  55. use POSIX;
  56.  
  57. if (isdigit($var)) {
  58. // integer
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement