perl实现大小写字母混排用于生成字典

前端之家收集整理的这篇文章主要介绍了perl实现大小写字母混排用于生成字典前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

例如输入全小写abc,则能够生成abc,Abc,aBc,ABc,abC,AbC,aBC,ABC:

#!/usr/bin/perl -w

$abc='abc';
while($abc){
        print $abc.$/;
        $abc = jia1($abc);
}

sub jia1{
        my ($words) = (@_);
        if($words =~ /^[A-Z]+$/){return 0}
        my @words_array = split('',$words);
        my $jinwei = 1;
        foreach (@words_array){
                if($jinwei == 1) {
                        if($_ =~ /^[a-z]$/){
                                $_ = uc $_;
                                $jinwei = 0;
                        }elsif($_ =~ /^[A-Z]$/){
                                $_ = lc $_;
                                $jinwei = 1;
                        }
                }
        }
        $words = join('',@words_array);
        return $words;
}

猜你在找的Perl相关文章