LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-13-2005, 10:36 AM   #1
eagle683
Member
 
Registered: May 2005
Posts: 38

Rep: Reputation: 15
easy perl question


I think I am just being an idiot, but this is driving me nuts,

in perl, I am trying to create a menu for a program I am writing

here is the code

while($stats ne "done" || $stats ne "none" || $stats ne "all")
{
if($stats =~ /^owner$/)
{
#do some stuff
}
elsif
{
#do some other stuff
}
#bla
#bla
#bla
else
{
print "not a valid option\n";
}
$stats = <STDIN>;
}

Where it says bla - there is another nested if loop.

If I enter none, done, or all - shouldn't the program skip the loop?
because it always gives the error message "not a valid option"

Thanks for any help

eagle
 
Old 07-13-2005, 11:06 AM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
Logical error: you're not saying what you mean.

This line:
Code:
while($stats ne "done" || $stats ne "none" || $stats ne "all")
should be this:
Code:
while($stats ne "done" && $stats ne "none" && $stats ne "all")
 
Old 07-13-2005, 03:09 PM   #3
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,994

Rep: Reputation: 76
Also, you haven't said how you're getting $stats. If you're reading it from a filehandle, make sure you chomp() it, otherwise you'll find newlines at the end of your string that can cause your matches to fail.
 
Old 07-13-2005, 06:45 PM   #4
puffinman
Member
 
Registered: Jan 2005
Location: Atlanta, GA
Distribution: Gentoo, Slackware
Posts: 217

Rep: Reputation: 31
You might also look into the Term::Prompt and Term::Menus modules on CPAN.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Easy question snowbird122 Linux - Newbie 2 09-11-2004 11:10 PM
Hiding code in PERL, perl gui question randomx Programming 1 06-26-2004 03:22 PM
Another Easy Question relic5 Linux - Software 3 09-28-2003 12:38 PM
Easy Question marlaina1 Linux - General 1 12-28-2001 07:02 AM
Very Easy Question linuxcam Linux - General 4 12-20-2001 12:58 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration