[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl-AnyPerl] need clarification on 'my' and 'use vars'




Folks,

I'd like some clarification on the advantages/disadvantages of using a
'use vars' statement vs. using 'my' to pre-declare a list of variables.
I usually use the 'my' list method to quiet '-w' warnings but saw
the 'use vars' technique in some sample code. Here's a clipping for
discussion:

#---
#!/usr/bin/perl -w

use strict;
use vars qw{$dbh $sth $sql @row};

#or
#my ($dbh, $sth, $sql, @row);
#---

My guess is that using 'my' with its limited scope, declares the variables
as file-level scope variables. The advantage is that they would be
available to subs in that script but not to a script calling this script. 
The 'use vars' line looks like it makes the variables globally available.
Correct? Is there an advantage to the latter? For example, connecting to
databases, working with sockets, etc.

Just wondering. Feedback appreciated.

Paul


==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-anyperl-request@macperl.org