Fri Sep 18 18:03:04 1998 Subject: Re: mod_perl (was Cookies) > This is going to get complicated and expose my superficial understanding > of programming -- so don't anyone hesitate to jump in with corrections > etc. > > I don't understand the difference, in perl, of using: > > my ($var1,$var2,$var3); > > vs. > > use vars qw ($var1 $var2 $var3) phoo.. large differences. the 'my' keyword tells the interpreter to use "dynamically scoped" variables. 'use vars' tells it to treat user-defined names as if they were built-ins. dynamic scoping means that the interpreter doesn't allocate memory to hold the data (and more specifically, define an entry in the symbol table) until control actually enters the function. normal variables are defined in the symbol table when the interpreter scans the code before execution, and usually stay defined for the entire life of the program. 'my' variables only exist as long as someone knows how to find them. 'use vars' takes names which are defined in the symbol table, and sort of "bumps them up" in terms of recognition. the effect is that you can say: use vars qw( $name1 $name2 &func_x ); the leave off the type-symbols in later code: $temp = name1; name2 = $temp; func_x ( name2 ); and so on. > My scripts were written using strict .... and I did some searching and > discovered that I might want to use "require CGI.pm" rather than "use > CGI.pm" owing to ..... it sounds like you're having problems with the 'use' directive. i haven't worked with mod_perl yet.. it's still on my to-do list, next to learning the Apache API.. but i can see how dynamic package loading could cause problems. another little-known feature introduced in perl5 is the addition of sequence blocks for execution. it's great for writing one-liners, because it's a way of chaining operations sequentially. the code: END { print "this is the end block\n"; } print "this is the main block\n"; BEGIN { print "this is the begin block\n"; } produces the following output: this is the begin block this is the main block this is the end block now.. the statement: use Package is equivalent to the statement: BEGIN { require "Package.pm"; &Package::import(); } which causes all necessary files to be read into memory and the appropriate namespace coordination to be done before the first line of normal code ever executes. if, as you say, global values get carried across from one execution to the next, 'use' statements would play merry hell with the namespace. > And if you don't use "use strict" or localize > variables then ..... could be trouble. 'my' variables should be safe for localization. 'use' statements may cause you trouble, but perl is so aggressive about distributing stuff in packages that i find the idea of complete incompatability strange. at very least, check out those sections of the documentation, to see if the authors offer any tips or warnings.