Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Re: Sorting Issues :(

by LostS (Friar)
on Jul 18, 2001 at 21:52 UTC ( [id://97793]=note: print w/replies, xml ) Need Help??


in reply to Re: Sorting Issues :(
in thread Sorting Issues :(

Sir, Your suggections works great... Now I have another issue dealing with this. Due to my users are complete morons... They may set the time as a HH:MM{AM/PM} without that space... What should I do to check for that space and if it isn't there add it?

Replies are listed 'Best First'.
"Moron" users
by petdance (Parson) on Jul 19, 2001 at 05:27 UTC
    Due to my users are complete morons...

    Be careful with those stones: One might call someone who uses a sentence as poorly constructed as that a "moron", too.

    Your users are not morons. They're human. What's more, they're humans who don't really need to worry about whether there's a space between before the AM/PM. Why should they waste their human brain cycles dealing with something that the machine can handle just as well?

    Remember why we're programmers: "Machines should work. People should think." The whole point of the machine is to take the drudgery off the human. Taking a snippy attitude at your users benefits no one.

    Fortunately, Perl makes this sort of drudgery simple to handle, as you've already seen.

    Take the path to the light of helpfulness, not to the darkness of insulting your customers.

    xoxo,
    Andy
    --
    Throw down the gun and tiara and come out of the float!

Re: Re: Re: Sorting Issues :(
by Masem (Monsignor) on Jul 18, 2001 at 21:55 UTC
    Try this (in the regex...):
    $time =~ /^(\d{1,2}):(\d\d)\s?([APM]{2})$/ #----------------------------^ Added this # And actually, now that I come to think of it, the # dealing with AM or PM problems may be better sorted using: $time =~ /^(\d{1,2}):(\d\d)\s?(AM|PM)$/

    Note that you ought to use this regex after the user submits the data and before you enter it, so that if a user gives something bogus, you catch it then, before the data goes in, as opposed to afterwards during the sort.

    -----------------------------------------------------
    Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain

      Man one day I hope to be as well versed in perl as you. :)
Re: Re: Re: Sorting Issues :(
by Hofmator (Curate) on Jul 18, 2001 at 22:04 UTC

    To be on the safe side it's probably best to allow whitespaces (or none) in some more places which would turn the regex into: $time =~ /^\s*(\d{1,2})\s*:\s*(\d\d)\s*([APM]{2})\s*$/The \s* matches zero or more whitespaces and as many as possible (greedy). So this allows for any of the following (_ equals whitespace):

    _12:00_AM__ 1_:_00_PM 2:20AM
    And then you could allow for leaving out of AM/PM and assuming a 24 hour clock .... but /me gets carried away ;)

    -- Hofmator

      All these suggestions rock... I work for a governent agency so... anyway to idiot proof the stuff helps :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://97793]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-24 19:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found