Re: find words not in an array

From: Joe Smith (joe_at_inwap.com)
Date: 03/28/05


Date: Mon, 28 Mar 2005 11:09:40 -0800

mbstevens wrote:
> # A: I like a subroutine version for clarity.
> foreach my $w (@wordlist) {
> if ($sought eq $w)

Your solution does not scale well. If @wordlist and @testlist
have 1000 words each, the brute-force method requires 1000000
string comparisons instead of just 2000 hash operations.
The answer found in the FAQ is better.
        -Joe



Relevant Pages

  • Re: subroutine definitions
    ... >> with much greater clarity. ... A '$' in the subroutine prototype means a scalar, ... > it will be passed to the subroutine as an array reference. ... Perl prototypes strikes me as primarily a seed of confusion. ...
    (perl.beginners)
  • module variable naming
    ... end subroutine init_method ... end module mymod ... some variable `q' from an algorithm. ... Now for reasons of clarity and readability, ...
    (comp.lang.fortran)