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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Matching Whitespace

 



kyfellar
Deleted

Apr 22, 2001, 6:50 AM

Post #1 of 2 (142 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?





BigRich
Novice

Apr 23, 2001, 3:00 AM

Post #2 of 2 (133 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"
}


BigRich


 
 


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

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