in reply to Variables from modules

our declares a variable to be valid within the block or file.

Use this code instead :

package Test; use strict; use vars qw/$foo/; $foo = "test"; 1;


update : as dave_the_m and ikegami have just said below, I was wrong. our can be used for that. So : code testing is good should be my new motto...

--
zejames

Replies are listed 'Best First'.
Re^2: Variables from modules
by dave_the_m (Monsignor) on Sep 16, 2004 at 14:46 UTC
    our declares a variable to be valid within the block or file.
    Er, no. our creates a lexically-scoped alias of a global variable. The variable is still accessible from any src file by providing the fully-qualified name. There is is no need for the the OP to use use vars, as my working code I posted earlier demonstrates.

    Dave.

Re^2: Variables from modules
by ikegami (Patriarch) on Sep 16, 2004 at 14:47 UTC
    Nope. our makes it so you don't have to use a fully qualified name when addressing the variable within the block or file. You can still access the variable from anywhere, because you never have to declare package variables (or whatever you call variables that aren't lexicals). I've tested it with our and it works great.