in reply to Mine or Ours
use strict; package foo; our $quux = "Howdy, world!\n"; # dump symbol table print "foo: $_ => $foo::{$_}\n" for keys %foo::; package bar; # dump symbol table print "bar: $_ => $bar::{$_}\n" for keys %bar::; print $quux; __END__ foo: quux => *foo::quux Howdy, world!
There you have the "does not necessarily create a variable" part - no variable is created in package bar. The variable $quux is shared between both packages - they would say "it's our $quux" if they could speak. Same applies for variables declared with our in different files. Having a file as
# file include.pl use strict; our $me; sub japh { print $me,"\n"; }
to be included in a main script
#!/usr/bin/perl use strict; our $me = "Just another perl hacker"; require "include.pl"; japh();
running the main script will output
Just another perl hacker
The $me variable is shared between the two files. That's what our means ;-)
--shmem
update: corrected "file scoped" to "lexical scoped". See Re^4: Mine or Ours.
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Mine or Ours
by gaal (Parson) on Jan 21, 2007 at 06:53 UTC | |
by shmem (Chancellor) on Jan 21, 2007 at 09:24 UTC | |
by gaal (Parson) on Jan 21, 2007 at 09:44 UTC | |
by shmem (Chancellor) on Jan 21, 2007 at 10:08 UTC | |
|
Re^2: Mine or Ours
by Herkum (Parson) on Jan 21, 2007 at 03:10 UTC |