Mohammed Khatib wrote:
> Hi Gurus,
>
> I've got the following "if" statement in my program:
>
> if ($rec =~ m!^tableofstatutoryrules((-table)?)((\d+)?)$!i)
>
> Note that the ((-table)?)((\d)?) section is optional, but if it matches, I
> want to be able to capture the \d+ in variable $4, WITHOUT receiving a
> warning when it doesn't match, which is 99% of the time.
>
> Why do I still get the warning when it doesn't match the optional part??
You can check to see if the $n vrbl is defined. Try:
if ($rec =~ /^tableofstatutoryrules($|-table(\d+)$)/i) {
print "table # = $2\n" if defined $2;
print "no table #\n" if not defined $2;
--
,-/- __ _ _ $Bill Luebkert ICQ=14439852
(_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED]
/ ) /--< o // // http://dbecoll.tripod.com/ (Free site for Perl)
-/-' /___/_<_</_</_ Castle of Medieval Myth & Magic http://www.todbe.com/
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/activeperl