CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
Matching Whitespace



Apr 22, 2001, 6:50 AM

Post #1 of 2 (214 views)
Matching Whitespace Can't Post

I have some error checking in my program and I need to make sure that the user keys in a valid command. One of the valid commands is whitespace or newline. Here is my section of code, but I can not figure out how to include newline character as a valid commmand:

elsif ($command !~ /^[h?qxadls]$/)
print "\nERROR: Not a valid command!\n"

Any ideas or suggestions?


Apr 23, 2001, 3:00 AM

Post #2 of 2 (205 views)
Re: Matching Whitespace [In reply to] Can't Post

Assuming that you just want to check if the user hit the enter (return) key, just add the ? quantifier (0 or 1) after your character class and it will match a blank line as well.

elsif ($command !~ /^[h?qxadls]?$/)
print "\nERROR: Not a valid command!\n"



Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives