View Full Version : Explicitly defining package names.
recluse
03-30-2002, 04:15 AM
When I ran my little wrote-it-to-learn-script I get an infinite loop, when running it with 'use strict' and warnings I get errors such as:
Global symbol "$good" requires explicit package name at reg_expressions.pl line 8.
As you may have guessed I need help with what it means to give a variable an explicit package name.
I have the Camel Book, so if you'd rather save yourself the typing time and just point out a section I should devour that'd be purdy nice of ya. :)
MattD
03-31-2002, 01:20 AM
use strict means that you must pre-delcare all your variables.
put a my ($good,$other,$variable,@names,%here); at the start of your code (dont take it literally ok ;)
if your getting into an infinite loop, make sure your loop exit criteria is correct, and make sure you havent forgotten a ++ somewhere
Matt D
recluse
03-31-2002, 05:15 AM
Here's the part of the file with the loop... there's other non related loop stuff also though.
open(ENIGMA, "solving_the_enigma.txt") or die "Can't open the file";
while(ENGIMA){
if(/\bwas\b/){
$wasCount++;
}
if(/\bas\b/){
$asCount++;
}
}
P.S. The text file is not infinitely long... heheh
Another question. Am I the only one annoyed by the double spacing of code?
nm the double spacing disappeared.
Feztaa
04-01-2002, 10:55 PM
Your file handle is wrong. "ENGIMA" should be "<ENIGMA>". Right now your while loop will keep executing until the string "ENGIMA" is false, which will never happen (infinite loop).
Once you change "ENGIMA" to "<ENIGMA>", it will properly loop over every line in the file.
recluse
04-02-2002, 01:12 AM
Oh duh! (recluse bangs head on desk in an attempt to learn through forced diffusion). Thank you Fetzza, I'll give that a shot when I reinstall my system.
vBulletin® v3.7.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.