Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hi !
1st : Tell us what you want from this script: I suppose it's : make someone enter a date until what he/she types is a "good" date (in "good" format). right ? If yes, you loop until the entry is OK ? 2nd : the format you show is not clear : It could be : 2008, January the 1st 2001, January the 8th, ... and so on It should be better to write it MM-DD-YY (for month, day, year). (FYI + :I'm french and we display dates as DD/MM/YY) for this format, the regex "could" be: (0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])-\d\d but : it ignores that the maximum number of days depends on the month( +28,29,30,31), it ignores leap years (February 28th or 29 th ?) You should use the function "timelocal()" from the standard module "Time::Local" : try to transform the date you have to validate into a +n "epoch" time (as the function time() returns) : if the function fai +ls, the date is wrong : this script seems to work: use Time::Local timelocal; my ($m,$d,$y); do { my $date; print "date (MM-DD-YY) ? "; $date=<>; chomp($date); ($m,$d,$y)=split(/-/,$date); $m -= 1; $y += 1900; } until(timelocal(0,0,0,$d,$m,$y));
I hope it adresses your need and will help you

In reply to Re: Regular expression for date by didess
in thread Regular expression for date by perlee

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-25 16:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found