in reply to Regex Unexplained Failure

Rolling your own email addressess validator is generally considered a bad idea. Just look at the 6.5k regexp written by Jeffrey Friedl (that is used in Email::Valid), or dig into the code of Abigail-II's RFC::RFC822::Address (which uses a different tecnique based on Parse::RecDescent).

Anyway, I don't have anything against reinventing wheels in order to learn. This leads to your question. Which I can't reply :) You just say that your RE fails when put into your cgi. It would be nice to know what is the string used in the matching, what was the desired output, and what was the actual output. And a small, but not smaller, piece of code that shows how your regex is used in its context.

Replies are listed 'Best First'.
Re: Re: Regex Unexplained Failure
by Flame (Deacon) on Aug 04, 2002 at 00:18 UTC
    This is the code I was using to test it:

    use GMS; #Own package, which in turn uses CGI, it was in there that I +was comenting out different lines to see if I could find the error while(chomp(my $temp = <>)){ print "Match\n" if($temp =~ m/^\w*?\@[a-z0-9.]*?\.(?-i:[a-z]){2,4}\ +z/i); }

    I would run it and enter an assortment of addresses, to see if they could work. Usually, just test@you.com while I was trying to locate the bug. Interestingly enough, it works fine when I use
    print "Match\n" if('test@you.com' =~ m/^\w*?\@[a-z0-9.]*?\.(?-i:[a-z]) +{2,4}\z/i);


    Though I can't imagine why it would operate differently just because of 'use CGI qw(:cgi);'...



    My code doesn't have bugs, it just develops random features.

    Flame ~ Lead Programmer: GMS

Re: Re: Regex Unexplained Failure
by Flame (Deacon) on Aug 04, 2002 at 03:22 UTC
    Here's another problem, now that I've managed to solve the dillema with why it was only sometimes failing. I'm stuck with ActiveState on a Win32 system, and Email::Valid does not want to run there. PPM refuses because there is no valid package for Win32, and I can't seem to get CPAN working. (I've been trying that off and on for the past year now... 10 different make programs and none of them work...)

    Any suggestions?



    My code doesn't have bugs, it just develops random features.

    Flame ~ Lead Programmer: GMS

      Have you tried Microsoft's nmake? I haven't had any problems with nmake in the past and wouldn't think you would either.

      To install Email::Valid, just download the gzip file from CPAN and check out the README, but it is probably just do the usual perl Makefile.PL/(n)make/(n)make test/(n)make install. Since this is a pure Perl module, there shouldn't be any other problems. The only problem I could see right now is that Email::Valid requires Mail::Address. Just make sure that it is installed before you try to install Email::Valid.

        nmake was the first one I tried, and I've had the least sucess with it, even though I have Visual C++.

        Also, is it just me, or is this a problem?



        My code doesn't have bugs, it just develops random features.

        Flame ~ Lead Programmer: GMS