in reply to Creating a whitelist

First, you should be using use strict; and use warnings;. Second you shouldn't be quoting integers:

my $found = 0; ... if ($found == 0){... # or better: if (! $found){... # or for truth: if ($found){...

Now, the way you have things set up, won't do an exact match, so if someone states an org as "hi", you'd match on "chia", "chitchat" etc.

It's very hard to tell what's failing without you specifying some examples of what people are sending in, and the contents of your @orgs array.

In fact, after re-reading your post, we'll absolutely need to know what the contents of both are... do the words in the dictionary contain special chars such as commas, periods etc. Does the $organization coming in? If the dictionary has one word per line and you're receiving things like Company, LLC, you'll have to split the $organization up, clean it if necessary, then change the logic. Depending on the above, the following example may not (or probably won't) work.

Please provide us with some more details.

...

I'd recommend grep for this job. That way, your @orgs don't get split into things like "Company," and "LLC". The whole "Company, LLC" will have to match, exactly:

use warnings; use strict; my $organization = "thre"; my @orgs = qw (one two three four); error_suspect_org() if ! grep {$organization eq $_} @orgs; sub error_suspect_org { die "not a valid org!\n"; }

Replies are listed 'Best First'.
Re^2: Creating a whitelist
by htmanning (Friar) on Jun 15, 2016 at 21:07 UTC
    Thanks for the great response. The database has a list of words on each line like, First, National, Bank. If someone enters "National Bank" it triggers the error even though both words are on the list. Point taken on quoting integers. I get the whitelist from the database like this:
    $pointer7 = $sth7->fetchrow_hashref; $good_orgs = $pointer7->{'good_orgs'}; @orgs = split /\n/,$good_orgs;
    I tried your code and it still triggers the error if the org has 2 words from the list in it. Hmm...
      The database has a list of words on each line like, First, National, Bank. If someone enters "National Bank" it triggers the error even though both words are on the list.
      "National Bank" does not match "First, National, Bank" because of the comma. Try stripping out the commas:
      $_ =~ s/,//g for @orgs;
        "National Bank" does not match "First, National, Bank" because of the comma. Try stripping out the commas:

        That still wouldn't match, because "National Bank" !~ /First National Bank/i;. Reversing the match would work in that instance, eg "First National Bank" =~ /National Bank/i;

        I'm curious as to why OP doesn't provide a list of allowed values that users can select from?