http://www.perlmonks.org?node_id=951356

TalsiOrah has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks ^_^ This is my very first post. I honestly did not think I would need to, but after much searching, I am left with no choice because it's making me think about switching to C. (I know I said it... Lol!) Well first off I am trying to create a very large AI bot that will be embedded into my next computer's ArchLinux. It will have voice recognition, and say some random quotes through a generated voice at random times to simulate actual intelligence. I know I think I'm crazy too. I most definitely fail, but it will be a very good learning experience. So here is my start off code taken from http://mind.sourceforge.net/perl.html
#!/usr/bin/perl -w # sub security; sub sensorium; sub emotion; sub think; sub volition; sub motorium; while (1) { security(); sensorium(); emotion(); think(); volition(); motorium(); } sub security { # security } sub sensorium { # sensorium print "Press ENTER or ESCAPE key: "; $_ = <STDIN>; exit if (/^\027/); } sub emotion { # emotion } sub think { # think } sub volition { # volition } sub motorium { # motorium } #---
The problem is that I cannot exit the loop at all unless I press <CONTROL>-C (^C). I thought that it might be trying to terminate just the sensory stub, and then looping back and executing it again. So I moved the "exit if" up into the actual while loop out of frustration, but to no avail. This is a screenie of the output: http://is100.imagesocket.com/images/2012/02/02/2425592-4k99.png I pressed enter twice, then I pressed the ESC key then enter, then finally ^C. That is the right hex for ESC correct? I was really hoping that I could find a way to close/exit the script with having to type into the terminal also. But nothing seems to be working right now. It should be such a simplistic script. I really cannot figure it out. I even tried chomping, and chopping. Help would very much be appreciated. I don't want to end my project before I haven't even started. I am merely a beginner, Thanks for your time ^_^