Determine if a string starts with an upper-case character in Perl -
i need make subroutine in perl determines if string starts upper-case character. have far following:
sub checkcase { if ($_[0] =~ /^[a-z]/) { return 1; } else { return 0; } } $result1 = $checkcase("hello"); $result2 = $checkcase("world");
that's correct. [a-z]
might not match uppercase accented characters depending on locale. better use /^[[:upper:]]/
.
also subroutine invocations shouldn't have $
character in front of them. i.e. should be:
$result1 = checkcase("hello"); $result2 = checkcase("world");
Comments
Post a Comment