下面是我检查单词是否以数字开头的代码:
#!/usr/bin/perl
my $domain_name = @ARGV;
my $first_letter = substr(($domain_name),0,1);
print STDERR "first letter is $first_letter \n";
if($first_letter eq '0' || $first_letter == 1
|| $first_letter == 2 || $first_letter == 3 || $first_letter == 4
|| $first_letter == 5 || $first_letter == 6 || $first_letter == 7
|| $first_letter == 8 || $first_letter == 9) {
print STDERR "$first_letter start with digit\n";
} else {
print STDERR "$domain_name does not starts with a digit\n";
}
但是当我打印时$first_letter
,它总是显示1
。请帮忙。