Problem with values - simple problem 
Author Message
 Problem with values - simple problem

I am trying to get the script to exit if the user enters q
what is happening is, if the user enters a word that begins with a q
(ex. que quick quest) the script terminates !

I want the script to terminate only if the user enters a single q

die "Bye !\n" if $search ==  /q/;
die "Bye !\n" if $search =~  /b[q]/i;
"                 " eq

Please let me know where I have made my mistake.

Thanks,
Matt

Sent via Deja.com
http://www.*-*-*.com/



Wed, 18 Jun 2003 00:41:48 GMT  
 Problem with values - simple problem

Quote:

>I am trying to get the script to exit if the user enters q
>what is happening is, if the user enters a word that begins with a q
>I want the script to terminate only if the user enters a single q

>die "Bye !\n" if $search ==  /q/;

                              ^^^

That is matching against the string in $_, not against $search.

I'll bet you retyped your code instead of copy/pasting it. Don't do that.

   die "Bye !\n" if $search eq "q\n";

or

   die "Bye !\n" if $search =~ /^q$/;

Quote:
>die "Bye !\n" if $search =~  /b[q]/i;

I'm not at all sure what you expected that to do. It requires
a "b" to match. You haven't said anything about the letter "b"...

--
    Tad McClellan                          SGML consulting

    Fort Worth, Texas



Wed, 18 Jun 2003 00:56:07 GMT  
 Problem with values - simple problem

Quote:

> I am trying to get the script to exit if the user enters q what is
> happening is, if the user enters a word that begins with a q
> (ex. que quick quest) the script terminates !

> I want the script to terminate only if the user enters a single q

> die "Bye !\n" if $search ==  /q/; die "Bye !\n" if $search =~
> /b[q]/i;
> "                    " eq

How about:
  die "Bye !\n" if $search =~ /^q$/;

--
Garry Knight



Wed, 18 Jun 2003 08:22:43 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. newline problem with messy output - v simple problem

2. A simple problem befuddling my simple head

3. Simple Problem

4. not so simple regex problem

5. LWP::Simple header information problems

6. Help needed with CGI script (a very simple problem)

7. problem with LWP::Simple

8. problem with simple script ...

9. simple Socket client/server program with problems using sockaddr_in()

10. (Simple) module install problems..

11. a simple problem

12. Simple Script Problems w/CHMOD

 

 
Powered by phpBB® Forum Software