in reply to Regex Question

One of the most scalable ways:
my @badwords = qw/pass admin qwerty/; #continue as you want if (grep { $pass =~ /$_/ } @badwords) { print "Bad password!" }

Replies are listed 'Best First'.
Re^2: Regex Question
by ikegami (Patriarch) on Jul 12, 2006 at 18:25 UTC

    Close.
    if (grep { $pass =~ /$_/ } map quotemeta, @badwords) {
    or
    if (grep { index($pass, $_) >= 0 } @badwords) {
    or
    my $re = join '|', map quotemeta, @badwords;
    if ($pass =~ /$re/) {

      Less scalable, as you cannot add regexes to @badwords ;)
        @badwords can't contain both regexps and words. For example, your solution will fail with words (e.g. f*ck won't work), mine will fail with regexps (e.g. f[u*]ck won't work). I assumed you wanted words since your called your array @badwords.

        Both solutions are fine (although the name @badwords is a bit misleading if it contains regexps) depending on what is needed.

Re^2: Regex Question
by Anonymous Monk on Jul 12, 2006 at 18:32 UTC
    or even use index() instead of the regex....
    for @badwords { print "shame on you" if index $pass, $_ > -1; }