Why won't this code work? - Printable Version +- Support Forums (https://www.supportforums.net) +-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87) +--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18) +---- Forum: Perl Programming Support (https://www.supportforums.net/forumdisplay.php?fid=31) +---- Thread: Why won't this code work? (/showthread.php?tid=21250) |
Why won't this code work? - HeyDev - 08-10-2011 Below is my code, basically if the answer is "Y" then the script runs a message if it's something else then it closes. Quote:#! usr/bin/perl RE: Why won't this code work? - AceInfinity - 08-22-2011 Try this: Code: #! usr/bin/perl This is just a simple example of how you would use <STDIN>, which is what you're using. <> is just a short version of standard input. Actually a better setup would be something like this: Code: #! usr/bin/perl I forgot about case handling. This script will make the response case insensitive, so an input that is "n" instead of "N" will be the same thing. Same thing with "y" and "Y". Otherwise an input that it doesn't recognize will exit as well. Essentially, this new code is the same as: Code: #! usr/bin/perl It's just that the other way is a little shorter. /i is used to define the value as case insensitive. Which is why it's the same thing as using the or definer "||" like above. Reason your initial code didn't work is because you didn't define the input with the newline input \n. You also don't need to use "system exit;" you can just use "exit;" in the script to exit the script from being interpreted. |