in reply to speedier text matching
If you go over the entire list for every word, it's just going to take a lot of time. You want a hash instead.
#!/usr/bin/perl use strict; use warnings; # the diamond operator is special: # supply filenames on commandline or provide input on STDIN and it jus +t works my @word = <>; chomp @word; my %in_list; undef @in_list{ @word }; # now all entries from @word are keys in %in_ +list for( @word ) { my @hook = grep { exists $in_list{ $_ } } ( substr( $_, 1 ), substr( $_, 0, length( $_ ) - 1 ), ); print "$_: @hook\n" if @hook; }
You go through the list of words, generating front and tail hooks for each, and then look up whether there such a key exists in the hash.
Makeshifts last the longest.
|
|---|