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


In reply to Sharing variables by Miguel

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.