Hi Guys
I was hoping this would be a problem because I am struggling with the whole
scope thing in Perl but here goes.
A section of my code.
require "$LIBRARY_DIR/castime_html.pm";
use CGI; # load CGI routines
use strict 'vars';
my $q = new CGI; # create new CGI object
Problem is $q is not visible to any subs in $LIBRARY_DIR/castime_html.pm.
Now I am assuming I can pass $q into each sub but that seems silly. $q has
methods as well as data that I want to use everywhere so I want to pass the
whole thing not just the data. If I have to pass the entire $q to each sub
why not just make it global to all?
Why is this a BAD THING?
I am assuming that the following would make $q global?
require "$LIBRARY_DIR/castime_html.pm";
use CGI; # load CGI routines
$q = new CGI; # create new CGI object
use strict 'vars';
I have read heaps about scope in Perl about how it works and what scope
applies. What I would really like is something to explain why. Why are
global vars no good, when would you use them, ect. Is there a resource that
explains the philosophy of scope rather that just the mechanics of what it
is?
Thanks for any pointers
Kevin