in reply to number of unique characters in a string
#!/usr/bin/perl -w use strict; print UniqueCount("1234567812") . "\n"; sub UniqueCount { my $string = shift; if ($string) { my %unique; return grep { !$unique{$_}++ } split //, $string; } else { return 0; } }
You will want to modify if you do not want to count spaces or if you want to be case insensitive
Hope this helps - happy hacking - L~R
Update:Dropped un-needed @array in grep
|
---|