#!/usr/bin/env perl use strict; use warnings; use List::Util 1.45 'uniqstr'; use Test::More; my @tests = ( [abcdefa => 0], [abcdef => 1], [xyz => 1], [zzz => 0], ); plan tests => 0+@tests; for my $test (@tests) { my ($str, $exp) = @$test; is length($str) == uniqstr(split //, $str), !!$exp; } #### $ ./pm_11146148_uniq_str_chars.pl 1..4 ok 1 ok 2 ok 3 ok 4 #### #!/usr/bin/env perl use strict; use warnings; use List::Util 1.45 'uniqstr'; use Test::More; my @tests = ( ['abc', abcdefa => 0], ['def', abcdefa => 1], ['abc', abcdef => 1], ['xyz', xyz => 1], ['xyz', zzz => 0], ['xy', zzz => 1], ); plan tests => 0+@tests; for my $test (@tests) { my ($tmpl, $str, $exp) = @$test; my %tmpls = map +($_ => 1), split //, $tmpl; my @chars = split //, $str; my @tmpl_chars = grep exists $tmpls{$_}, @chars; is 0+@tmpl_chars == uniqstr(@tmpl_chars), !!$exp; } #### $ ./pm_11146148_uniq_str_chars_2.pl 1..6 ok 1 ok 2 ok 3 ok 4 ok 5 ok 6