Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (/D/) { print "has nondigitsn" }
- if (/^d+$/) { print "is a whole numbern" }
- if (/^-?d+$/) { print "is an integern" }
- if (/^[+-]?d+$/) { print "is a +/- integern" }
- if (/^-?d+.?d*$/) { print "is a real numbern" }
- if (/^-?(?:d+(?:.d*)?&.d+)$/) { print "is a decimal numbern" }
- if (/^([+-]?)(?=d&.d)d*(.d*)?([Ee]([+-]?d+))?$/)
- { print "a C floatn" }
- sub is_int {
- $str = $_[0];
- #trim whitespace both sides
- $str =~ s/^s+|s+$//g;
- #flatten to string and match dash or plus and one or more digits
- if ($str =~ /^(-|+)?d+?$/) {
- print "yes " . $_[0] . "n";
- }
- else{
- print "no " . $_[0] . "n";
- }
- }
- is_int(-12345678901234); #yes
- is_int(-1); #yes
- is_int(23.); #yes
- is_int(-23.); #yes
- is_int(0); #yes
- is_int(+1); #yes
- is_int(12345678901234); #yes
- is_int("t23"); #yes
- is_int("23t"); #yes
- is_int("08"); #yes
- is_int("-12345678901234"); #yes
- is_int("-1"); #yes
- is_int("0"); #yes
- is_int("+1"); #yes
- is_int("123456789012345"); #yes
- is_int("-"); #no
- is_int("+"); #no
- is_int("yadz"); #no
- is_int(""); #no
- is_int(undef); #no
- is_int("- 5"); #no
- is_int("+ -5"); #no
- is_int("23.1234"); #no
- is_int("23."); #no
- is_int("--1"); #no
- is_int("++1"); #no
- is_int(" 23.5 "); #no
- is_int(".5"); #no
- is_int(",5"); #no
- is_int("%5"); #no
- is_int("5%"); #no
- use POSIX;
- if (isdigit($var)) {
- // integer
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement