in reply to OUR declaration
$ourVAR = "123 ABC"; { my $ourVAR = "456 RST"; print "my packAA ourVAR = $ourVAR \n"; } print "our packAA ourVAR = $ourVAR \n"; __END__ my packAA ourVAR = 456 RST our packAA ourVAR = 123 ABC
In your example, you don't delimit the scope for the my version of $ourVAR, so it's valid unto the rest of the file.
our variables are shared variables in two ways: they are visible to code
package Foo; our $foo = 'bar'; package main; print $foo,"\n"; # bar
# file foo.pl use strict; our $shared = "one fish";
# file bar.pl use strict; our $shared =~ s/e f/e half f/;
#/usr/bin/perl use strict; our $shared; require "foo.pl"; require "bar.pl"; print $shared,"\n"; __END__ one half fish
They behave just like they are qualified - with my, and our.
--shmem
_($_=" "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: OUR declaration
by ioannis (Abbot) on Sep 23, 2006 at 10:19 UTC |