in reply to (code)) CGI.pm - CSS, tables... (deprecated by node 50167)

In the following code you have already declared the variables with use vars, therefore you do not need to declare them again with my:

use vars qw($type $expires $css $title $tm $file $mod); # declare variables my $type = 'text/html'; # HTML document type my $expires = 'now'; # browser page expiration my $css = './ybiC.css'; # Cascading Style Sheet my $title = 'CGI, CSS and Tables'; # HTML page title my $tm = localtime; # current host time my $file = '/var/www/htdocs/ybiC.cgi'; # this file my $mod = ctime(stat($file)-> mtime); # most recent modified time

So, if I am not mistaken, you can do it like so:

use vars qw($type $expires $css $title $tm $file $mod); # declare variables $type = 'text/html'; # HTML document type $expires = 'now'; # browser page expiration $css = './ybiC.css'; # Cascading Style Sheet $title = 'CGI, CSS and Tables'; # HTML page title $tm = localtime; # current host time $file = '/var/www/htdocs/ybiC.cgi'; # this file $mod = ctime(stat($file)-> mtime); # most recent modified time

I am guessing that that may speed things up slightly.

Update to first suggestion: I Benchmarked both ways and found that your way is faster anyway. I guess that I was mistaken.

Also, I don't know the reason for this but I keep getting a "Too late for "-T" option." error when I run it using ActivePerl.

Good luck.

Zenon Zabinski | zdog | zdog7@hotmail.com

Replies are listed 'Best First'.
RE: RE: CGI.pm for CSS, tables, pet tricks
by davorg (Chancellor) on Aug 14, 2000 at 17:52 UTC

    use vars and my create variables in two completely different ways. use vars will create package variables which live in the *main:: typeglob. my creates a completely separate set of lexical variables that just happen to have the same names.

    Having created the package variables, you then 'mask' them by declaring the lexical variables. The only way to accessthem would be to use the fully qualified variable name (like $main::type, etc.)

    In summary, you don't need both sets of declarations and, in fact, you're declaring one set of variables that you never use.

    --
    <http://www.dave.org.uk>

    European Perl Conference - Sept 22/24 2000, ICA, London
    <http://www.yapc.org/Europe/>
      What you say makes sense, davorg.   Do I eliminate the redundancy by removing "my" from each of the second declarations, like so?

      use vars qw($type $expires $css $title $tm $file $mod); $type = 'text/html'; $expires = 'now'; $css = './ybiC.css'; $title = 'CGI, CSS and Tables'; $tm = localtime; $file = '/var/www/htdocs/ybiC.cgi'; $mod = ctime(stat($file)-> mtime);

      I like "use vars qw() for keeping me mindful of all the script's variables.   But if there are reasons for pitching it and using "my", please enlighten me.

      Update: Oops. Had I re-read zdog's reply above, I would have asked this question differently.   <sheepish grin>
          cheers,
          ybiC

        zdog's tests would seem to indicate that lexical variables are faster than package variables, so if speed is important to you go with my, otherwise I don't know of any reason to choose one in preference to the other so just go with whatever you feel most comfortable with.

        --
        <http://www.dave.org.uk>

        European Perl Conference - Sept 22/24 2000, ICA, London
        <http://www.yapc.org/Europe/>