http://qs321.pair.com?node_id=28749


in reply to charachter classes, and a misunderstanding...

The second program says yes if there is at least one character not in the class, not if all characters are not in the class.

You want something like:

... if (/^[^yhnujmikolp]+$/i) { ...
which says "from the beginning to the ending, are they all not in this class".

This is a common problem when people negate things too much: the negations stack up in the wrong direction. Me, I avoid that kind of regex, and ask for what I want, which will also be faster:

@ARGV = qw(/usr/dict/words); my $longest = ""; while (<>) { next unless length > length $longest; # too short next if /[^qwertasdfgzxcvb\n]/i; # wrong hand $longest = $_; } print $longest;
And this finds "aftereffect", as you noted. But with a lot less code, as I'm often prone to do. {grin}

-- Randal L. Schwartz, Perl hacker