learn2earn has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: help with a regex
by Corion (Patriarch) on Feb 18, 2010 at 14:54 UTC
Re: help with a regex
by moritz (Cardinal) on Feb 18, 2010 at 14:59 UTC
    $mday =~ /\A(1|18)\z/

    Read perlre to find out what it means.

    Also you could use hashes for the months.

Re: help with a regex
by keszler (Priest) on Feb 18, 2010 at 15:02 UTC
    my problem is that on my third regex it matches any day that has a one in it which is not what I want

    Your regex is not anchored, so you're matching either a string that contains '1' anywhere, or a string that contains '18' anywhere.

    Check perlre for the use of ^, $, \A, \Z, and \z.

Re: help with a regex
by vmsathiya (Initiate) on Feb 18, 2010 at 15:03 UTC

    Try this modified code

    my @abbr=qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); if ($abbr[$mon]=~/Jan|Feb|May|Jul|Sep|Oct|Nov|Dec/) { # $response writes are old code debug write outs.. $Response->wri ++te("$abbr[$mon] $mday"); if (($abbr[$mon]=~/Jan/) && ($mday=~/^(1|18)$/)) { #close chat for these days.. $str.="</config>"; return $str; #$response->write("Happy New Year"); }