in reply to Anagram matching
sub is_anagram { my ($word, $test) = @_; foreach my $letter (split(//, $word)) { return unless $test =~ s/$letter//; } return if $test; # leftovers return 1; }
A regex isn't the most efficient method for approaching this (and this example is probably the least efficient of all), but it's easy to understand. Many of the optimizations people made in Difference Of Two Strings can probably be applied here.
|
|---|