This is the second post in the How To Ask a Question (With Test::More) series, and assumes you have read the first, main post.
In this installment, we learn how to use Test::More::like($string, $regex) and the qr quotelike operator to ask regex questions in a sane way. Let's dive right in.
******************BEGIN QUESTION TEMPLATE************************
O Wise Monks, I can't get this regex to do what I want it to do. As you can see, it fails two tests.
I'm on Windows XP system using the standard ActiveState perl distribution.use warnings; use strict; use Test::More qw(no_plan); my $emailsregex = qr/\w+@\w+\.(net|com|org)/; while (<DATA>) { like($_, $emailsregex) } __DATA__ timmytimmers@aol.com hillary-hillers@aol.com garbygerbil@herbill.gerbil.org garbygerbil@herbill.gorgil.org reginald_reggers@aol.com
I got both standard and error output out of my test, into one output file, by running this with emailsregex.pl > output.txt 2>&1 output.txt.
The output I got was
ok 1 ok 2 not ok 3 # Failed test (emailsregex.pl at line 8) # 'garbygerbil@herbill.gerbil.org # ' # doesn't match '(?-xism:\w+@\w+\.(net|com|org))' not ok 4 # Failed test (emailsregex.pl at line 8) # 'garbygerbil@herbill.gorgil.org # ' # doesn't match '(?-xism:\w+@\w+\.(net|com|org))' ok 5 1..5 # Looks like you failed 2 tests of 5.
What the heck am I doing wrong?
******************END QUESTION TEMPLATE************************
(Debugging the regex is left as an exercise for the reader.)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: How to Ask a Regex Question (with Test::More) (repost, with Sitedocclan approval)
by kvale (Monsignor) on Aug 06, 2005 at 14:31 UTC | |
Re: How to Ask a Regex Question (with Test::More) (repost, with Sitedocclan approval)
by Eimi Metamorphoumai (Deacon) on Aug 08, 2005 at 15:39 UTC | |
by eric256 (Parson) on Aug 08, 2005 at 17:13 UTC | |
Re: How to Ask a Regex Question (with Test::More) (repost, with Sitedocclan approval)
by chanio (Priest) on Aug 07, 2005 at 00:30 UTC |
Back to
Tutorials