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

I need help debugging some code I wrote for an exercise from my perl tutorial book, it's for validating time. here it is:
$mytime = <STDIN>; chomp $mytime if ($mytime =~ /([10-12]|[1-9])\:[0-59](am|pm)/i) {print "$time is a valid time.";}
any help will be greatly appreciated. and if it helps, I'm using MacPerl 5.20r4. Thanks!

Replies are listed 'Best First'.
Re: need help debugging code
by ignatz (Vicar) on Jul 21, 2002 at 04:10 UTC
    Make sure that every line of your code ends with a ;
    ()-()
     \"/
      `                                                     
    
      Also check your variables, $mtime vs $time.

      -Nitrox

Re: need help debugging code
by BUU (Prior) on Jul 21, 2002 at 04:15 UTC
    and your regex, the [10-12] isnt doing what you think it is. Namely x-z works on two characters,x to z in this case. Try splitting it into two columns, and validate all the digits that can be in the first column, then validate all theones in the second one.
Re: need help debugging code
by Vulturejoe (Novice) on Jul 21, 2002 at 07:31 UTC
    Ok, I've got it running now . Thanks alot, don't see how I could've missed that.