Perl Keyboard Inputs
I'm messing around with Perl (fro the first time) and I'm trying to figure how to let the user input with the keyboard. This is part what I have so far:
$answer = <STDIN>;#Line 7
chomp ($answer = <>);
The errors that I get are:
Global symbol "$answer"requires explicit package name at/home/me/projects/sweather/./sweather.pl line 7.
Global symbol "$answer"requires explicit package name at /home/me/projects/sweather/./sweather.pl line 8.
Global symbol "$answer"requires explicit package name at/home/me/projects/sweather/./sweather.pl line 9.
Keyboard inputs are usually pretty easy to do in other languages. I was folloowing a tutorial on the Internet. Does anybody have any suggestions?
If you do
which is a good idea, you need to declare vars before using them, like C.
I can recommend the Llama book (Learning Perl) if you haven't already got it.
Here's the lang pages, inc examples: http://perldoc.perl.org/
You can use them instead of buying Programming Perl, but I highly recommend Perl Cookbook if you are serious about learning Perl; lots of pre-worked examples with explanations.
I made a few changes so that it works now. First of all I noticed you never seemed to prompt the user for a value for $answer but were trying to read stdin anyways. I will highlight the parts I have added / changed.
|All times are GMT -5. The time now is 02:07 PM.|