Ben Edwards wrote:
On 23/05/07, Rob Dixon <[EMAIL PROTECTED]> wrote:
Ben Edwards wrote:
>
> Ime a bit confused about globals, I know they should be used with care
> but....
>
> Currently I am using $::var witch seems to work.

There's no reason to use $::var - it's the same as $main::var so use that
if it's what you mean.

> 'our var' also seems to work.

Work how?

> Cant find any documentation with a discussion of this that answerers
> my question totally.

And that question would be...?

> what is the conversion with globals?

I can't imagine what you mean by this. There is no conversion.

What are you trying to do Ben? It's actually quite unlikely that you need
'global' variables (by which you mean package variables) at all. What can't
you do if you declare everything using 'my'?

Ime changing some very badly written - almost everything is done in
callbacks.  We are slowly re-writing it but as it is a production
system we dont want to take a  bit bang approach yet.  This is partly
cos there is stuff that we probably dont need but I need to get to
know the perl better to verify this.

The main thing that I think is going to be a global (for now) is the
database connection.

We have something like

$dbh = DBI->connect....

For now I want to make $dbh available throughout the whole script and
am using $::dbh, but as you said maybe this should be $main::dbh.

By conventions I mean good practice, if there is such thing for globals;)

Is this any help?

Yes it is, thank you. But there's still no need for package variables unless
you're using multiple packages or multiple source files and need to share the
same data across more than one. Typically a database handle would be declared
lexically and assigned at the start of your program, and a simple

 my $dbh = DBI->connect($dsn, $user, $pass);

will allow you to access the handle through the rest of the file.

You may need more than this, however, if your script is spread across multiple
source files.

HTH,

Rob

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to