stevej@synopsys.synopsys.com (Steven Jukoff) (06/16/90)
Does Perl have functions similar to isascii(), isprint(), isalpha(), etc? These are available in the 'C' language via: #include <ctype.h>
tchrist@convex.COM (Tom Christiansen) (06/16/90)
In article <536@synopsys.COM> stevej@synopsys.synopsys.com (Steven Jukoff) writes: >Does Perl have functions similar to isascii(), isprint(), >isalpha(), etc? If you really wanted subroutines for these, you might do something like these (untested): sub isspace { $_[0] =~ /^\s+$/; } sub isdigit { $_[0] =~ /^\d+$/; } sub isalnum { $_[0] =~ /^[a-z\d]+$/i; } or more likely sub isalnum { $_[0] =~ /^\w+$/; } sub isalpha { $_[0] =~ /^[a-z]+$/i; } sub iscntrl { $_[0] =~ /^[\000-\037]+$/; } sub isascii { $_[0] =~ /^[\000-\177]+$/; } sub islower { $_[0] =~ /^[a-z]+$/; } sub isupper { $_[0] =~ /^[A-Z]+$/; } sub isxdigit { $_[0] =~ /^[\da-f]+$/i; } sub tolower { $_[0] =~ y/A-Z/a-z/; } sub toupper { $_[0] =~ y/a-z/A-Z/; } Except that I'd wouldn't really write them as subroutines. I'd just do the compare against the variable directly. One of the most basic things about perl is regular expressions; that's why it's got operators for it. Whether hiding this stuff in subroutines improves readability is debatable. --tom -- Tom Christiansen {uunet,uiucdcs,sun}!convex!tchrist Convex Computer Corporation tchrist@convex.COM "EMACS belongs in <sys/errno.h>: Editor too big!"