in reply to print() on closed filehandle..

Get rid of the "used only once" by putting an our $portalserver; in your code (doesn't have to be in any particular scope; just has to happen before the main script is done compiling).  Use use vars wq/$portalserver/; instead if on perl older than 5.6.0 or if the variable has a different package name (e.g. use use vars qw/$foo::bar/;).

Replies are listed 'Best First'.
Re: Re: print() on closed filehandle..
by wolis (Scribe) on Feb 05, 2004 at 05:00 UTC
    Ah.. so 'our' is like 'global' in other languages? (opposite of 'my')?
    ___ /\__\ "What is the world coming to?" \/__/ www.wolispace.com
      Not exactly. global variables just spring into existence when the compiler notices them, so our() doesn't really declare them, per se. our() serves a few different purposes. One is to get rid of the "used only once" warning (which is intended to help catch typos in variable names). If you run with use strict "vars"; turned on, you'll usually have to use our() on user variables native to a package but not qualified by a package (aka namespace). This is also intended to help catch typos in variable names.

      our() also will hide a my() variable for a certain scope:

      perl -we '$x = "global"; my $x = "local"; our $x; print $x' global
      Here there are two different $x variables; the global $x that lives in the symbol table for the main:: package, and a lexical $x that lives in a pad (a kind of temporary storage attached to each subroutine or source file (though one pad can have multiple variables of the same name with different scopes within the subroutine)). Normally in the scope of a my($var), $var will refer to the lexical variable. our($var) can be used to override that to the end of the enclosing block.