slinky773 has asked for the wisdom of the Perl Monks concerning the following question:
OK, easy enough:See whether you can produce a pattern to match a standard time format. + All the following should be acceptable: 12:00am, 5:00pm, 8:30AM. These sho +uld probably not be accepted: 3:00,2:60am, 99:00am, 3:0pm.
However, this is the terminal output:#!/usr/bin/perl -w use strict; use warnings; print "Type in the current time!\n"; my $input = <STDIN>; while($input) { if($input =~ m/(\d)*(\d):(\d)(\d)(\w)(\w)/ | $input =~ m/(\d)*(\d) +:(\d)(\d)(\s)(\w)(\w)/) { if($1 > 1 || $2 > 2 || $3 > 6) { print "That is not a valid time!\n"; print "Type the time again.\n"; $input = <STDIN>; } else { print "That is a valid time!\n"; $input = 0; } } else { print "Please be more specific.\n"; $input = <STDIN>; } }
Er... any help here? For added clarity, this is line 13:Last login: Thu Aug 18 11:28:44 on ttys000 youngs-mac-mini:~ fenimore$ cd ~/Documents youngs-mac-mini:Documents fenimore$ perl TimeChecker.pl Type in the current time! 4:90 Please be more specific. 4:30AM Use of uninitialized value $1 in numeric gt (>) at TimeChecker.pl line + 13, <STDIN> line 2. That is not a valid time! Type the time again. 12:30PM That is a valid time! youngs-mac-mini:Documents fenimore$
if($1 > 1 || $2 > 2 || $3 > 6)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Weird Regexes Stuff
by toolic (Bishop) on Aug 18, 2011 at 17:08 UTC | |
| |
Re: Weird Regexes Stuff
by Samy_rio (Vicar) on Aug 18, 2011 at 18:00 UTC | |
by AnomalousMonk (Archbishop) on Aug 18, 2011 at 18:11 UTC | |
by AnomalousMonk (Archbishop) on Aug 19, 2011 at 07:47 UTC |