Generate list of all possible permutations of a string

后端 未结 30 2844
故里飘歌
故里飘歌 2020-11-22 15:10

How would I go about generating a list of all possible permutations of a string between x and y characters in length, containing a variable list of characters.

Any l

30条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 15:38

    In Perl, if you want to restrict yourself to the lowercase alphabet, you can do this:

    my @result = ("a" .. "zzzz");
    

    This gives all possible strings between 1 and 4 characters using lowercase characters. For uppercase, change "a" to "A" and "zzzz" to "ZZZZ".

    For mixed-case it gets much harder, and probably not doable with one of Perl's builtin operators like that.

提交回复
热议问题