[EMAIL PROTECTED] (Stas Bekman) wrote:
>A combination of C<strict> and C<vars> pragmas keeps modules clean and
>reduces a bit of noise.  However, the C<vars> pragma also creates
>aliases, as does C<Exporter>, which eat up more memory.  When
>possible, try to use fully qualified names instead of C<use vars>.

I have to disagree with this benchmark.  The aliases take up only the
tiniest bit of memory, much less than your benchmark seems to indicate. 
What your benchmark shows is the code size of the 'vars.pm' module
itself, not the memory cost of making aliases.  Observe:

-------Code:------------------------------------------------------------
package MyPackage;
use strict;
use vars;
@MyPackage::ISA = qw(CGI);
$MyPackage::VERSION = "1.00";

system "ps -lp $$";
-------Output:---------------
USER    PID %CPU %MEM   VSZ  RSS TTY      S    STARTED         TIME COMMAND
ken   59972  0.0  0.1 3.37M 696K pts/4    S  + 19:50:10     0:00.14 ./vars.pl

-------Code:------------------------------------------------------------
package MyPackage;
use strict;
use vars qw(@ISA $VERSION);
@MyPackage::ISA = qw(CGI);
$MyPackage::VERSION = "1.00";

system "ps u -p $$";
-------Output:---------------
USER    PID %CPU %MEM   VSZ  RSS TTY      S    STARTED         TIME COMMAND
ken   54842  0.0  0.1 3.37M 696K pts/4    S  + 19:50:39     0:00.13 ./vars.pl

-------Code:------------------------------------------------------------
package MyPackage;
use strict;
use vars qw(@ISA $VERSION);
@ISA = qw(CGI);
$VERSION = "1.00";

system "ps u -p $$";
-------Output:---------------
USER    PID %CPU %MEM   VSZ  RSS TTY      S    STARTED         TIME COMMAND
ken   58422  0.0  0.1 3.37M 696K pts/4    S  + 19:52:07     0:00.13 ./vars.pl
------------------------------------------------------------------------

(This is using 5.004_04, I didn't have GTop.pm available for fine
resolution of memory.)

So there's no visible difference.  Since some module somewhere in your
processes will be certain to 'use vars', you don't get any real benefit
from leaving it out in one place, and you increase the chances of making
typos.

To confirm, a couple of one-liners:

[~/bin/test],7:56pm% perl -mvars -e 'system "ps u -p $$"'
USER    PID %CPU %MEM   VSZ  RSS TTY      S    STARTED         TIME COMMAND
ken   79047  0.0  0.1 3.34M 680K pts/4    S  + 19:57:23     0:00.13 perl -mvars -e 
system "ps u -p $$"

[~/bin/test],7:57pm% perl -e 'system "ps u -p $$"'
USER    PID %CPU %MEM   VSZ  RSS TTY      S    STARTED         TIME COMMAND
ken   55275  0.0  0.1 3.00M 336K pts/4    S  + 19:57:39     0:00.06 perl -e system "ps 
u -p $$"



  -------------------                            -------------------
  Ken Williams                             Last Bastion of Euclidity
  [EMAIL PROTECTED]                            The Math Forum

Reply via email to