in reply to Re^12: the "our" declaration ?!! (special vars)
in thread the "our" declaration ?!!

> If you think it is just a question of what I am "used to", then you need to read more carefully.

actually I read it all carefully but it's complicated to interpret a page full of coding *theory* without any code *examples*...and English is actually not my best foreign language ...

>If you don't understand how "vars" works, then you should correct that, because it is really simple and occasionally useful.

well the perldoc says

the "use vars" and "use subs" declarations are not BLOCK-scoped. They are thus effective for the entire file in which they appear.
but actually - as I only found out by experimenting - it depends on the scope of "package" which confused me!

to make it clearer some code:

use strict; $\="\n"; use vars qw($x); $x="main"; { print $x; package one; use vars qw($x); $x="one"; print $x; } print $x; __END__ main one main
But where's the problem to import variables with our ??? Could you give me please a code example?

Cheers Rolf

Replies are listed 'Best First'.
Re^14: the "our" declaration ?!! (special vars)
by ikegami (Patriarch) on Jan 21, 2009 at 21:01 UTC

    Indeed. The vars and subs pragmas affect packages, not files. Their effects can even span files, if more than one file use the same package.

    Since imported variables aren't subject to use strict, and imported subs can override core functions, vars and subs simply export new vars and subs (respectively) into the caller's package.