Esteemed Monks,
Since I don't see anyone (those authors that suggest good practices) sharing variables across modules this way, I wonder if I'm doing the right thing.
For example:
'test' is the main program;
'vars.pl' declares and initializes some variables I'll use across the modules;
'test.pm' is a module.
File: test
------------------------------------------
#!/usr/bin/perl -Tw
$|++;
use strict;
BEGIN {
require "./vars.pl";
}
START: hello_world();
sub hello_world {
print $::q->header, $::q->start_html,
$::test->SayHelloTo({WHO=>"World!"}),
$::q->end_html;
}
File: vars.pl
------------------------------------------
#!/usr/bin/perl -Tw;
use strict;
use lib './';
use CGI;
our $q = CGI->new;
use test();
our $test = test->new;
File: test.pm
------------------------------------------
package test;
use strict;
use vars qw($VERSION);
$VERSION = 1.0;
sub new {
my $class = shift;
$class = ref($class) || $class;
my $self = {};
bless($self, $class);
return $self;
}
sub SayHelloTo {
my $self = shift;
$self->{PARAMS} = shift if @_;
my $params = $self->{PARAMS} || '';
return $::q->p("Hello", $params->{WHO});
}
1;
This code doesn't output any error or warning and it doesn't look slow - well, it's a short example anyway - so, my question is: is this a tremendous error? what is your advice?
Miguel