in reply to Re^2: Need RegExp help - doing an AND match
in thread Need RegExp help - doing an AND match

See perlre.

/./ will match the character '.', but will also match many other characters. What you likely want is to quote the dot, so it loses its special meaning:

"." =~ m!\.!

Update: GrandFather spotted a missing ! at the end of the regular expression

Replies are listed 'Best First'.
Re^4: Need RegExp help - doing an AND match
by Anonymous Monk on Jul 01, 2007 at 20:30 UTC
    Yes, I know what you mean but I'm not matching explicit text - here is an example:
    @words = ("filename" , "file.txt"); $line = "my file is file.txt";
    I want to search this line and save it in a variable for later. These work assuming no lines contain both words:
    $file = (grep{$line =~ /$_/i} @words)[0]; or foreach (@words) { next if($line !~ /$_/i); $file = $_; }
    So both work ($file is nonempty) but not good.
    Problem is that I will need to pass a variable into my RegExp for my search - which may or may not contain a "."

      You seemed to have missed the quoting of dot part in Corion's reply. In any case, refer to the quotemeta function description, usage of which would be something like ...

      my @words = map { quotemeta $_ } ( "filename" , "file.text" );

Re^4: Need RegExp help - doing an AND match
by Anonymous Monk on Jul 01, 2007 at 21:06 UTC
    Apologies all. I've re-read all posts here and List::Util first does the trick. Thanks to all who replied!