I am new to Perl and I have been following a book. All is well, except for whenever I try to initialize a variable as shown by the book, I am getting an error like below. Kindly tell me what should I do in order to avoid this error?
Code:
#!/usr/bin/perl -w
use 5.014;
use strict;
use utf8;
$radius = <STDIN>;
$circum;
if ($radius<0){
$circum = 0
} else{
$circum = 2*3.141*$radius;
}
print $circum."\n";
Errors: Global symbol "$radius" requires explicit package name at ./example1 line 6. Global symbol "$circum" requires explicit package name at ./example1 line 7. Global symbol "$radius" requires explicit package name at ./example1 line 8. Global symbol "$circum" requires explicit package name at ./example1 line 9. Global symbol "$circum" requires explicit package name at ./example1 line 11. Global symbol "$radius" requires explicit package name at ./example1 line 11. Global symbol "$circum" requires explicit package name at ./example1 line 14. Execution of ./example1 aborted due to compilation errors.
Also, I have read somewhere in the forums about 'our' and 'my' keywords. Using these seems to work. But, is it compulsory to use these keywords. If so, I think it is strange that the book did not include them.
use strict;and it won't be compulsory. - Elliott Frischuse strict;anduse warnings;should start every Perl script so indeed it is strange that your book did not tell you about this stuff. - DeVadderuse 5.014automatically loadsstrict(andwarnings) - mob