Skip to content

Instantly share code, notes, and snippets.

@lukasvermeer
Created January 10, 2016 14:00
Show Gist options
  • Save lukasvermeer/ce54413a3860d7f0b999 to your computer and use it in GitHub Desktop.
Save lukasvermeer/ce54413a3860d7f0b999 to your computer and use it in GitHub Desktop.
Given a word and a file with more words, find anagrams.
use strict;
use warnings;
use Data::Dumper;
die "Malfunction. Need input." unless $ARGV[0] and $ARGV[1];
my @m = sort split('',lc($ARGV[0]));
my $m = (join "?", @m) . "?";
#print Dumper $m; die;
open(W, $ARGV[1]);
while (my $line = <W>) {
chomp($line);
if((join "",sort split('',lc($line)))=~/^\s*$m$/
and length $line == length $ARGV[0])
{ print $line . "\n"; };
}
close(W);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment