【发布时间】:2019-10-22 12:05:50
【问题描述】:
我想在 Perl 中为我的新网站显示不同国家的税务说明。根据我使用的 API 中的各个国家/地区,我得到了所有大写字母的税收说明。
我不希望数组中包含单个单词 VAT 或 SGST。我想要数组中只有多个税收描述词的词。相反,它应该直接显示 $word
以下是代码:
sub maybe_ucfirst {
my ($word) = @_;
my %ignore = map { $_ => undef } qw(GST AZ);
return exists $ignore{$word} ? $word : ucfirst Lc $word;
}
my @inputs = ('AUSTRALIA GST', 'AZ COUNTY TAX', 'NEW ZEALAND GST', 'VAT');
for my $s (@inputs) {
$s =~ s/(\w+)/maybe_ucfirst($1)/eg;
say $s;
}
这里是输入和输出:
1: Input: ‘AUSTRALIA GST’
Output: ‘Australia GST’
2. Input: ‘AZ COUNTY TAX’
Output: ‘AZ County Tax’
3. Input: ‘NEW ZEALAND GST’
Output: ‘New Zealand GST’
4. Input: ‘VAT’
Output: ‘Vat’
5. Input: ‘SGST’
Output: ‘Sgst’
我希望单个税收描述词的输出为:
1. Input: ‘SGST’
Output: ‘SGST’
2. Input: ‘VAT’
Output: ‘VAT’
任何人都可以帮助如何在 Perl 中解决这个问题吗?
【问题讨论】: