On Sun, Oct 02, 2005 at 08:49:30AM -0400 Jeff 'japhy' Pinyan wrote:
...................
>
> If you REALLY want to use package variables instead of lexicals, then you
> need to follow the instructions in the 'strict' documentation for
> declaring your global variables:
>
> use strict;
> our ($foo, @foo);
>
> $foo = ...;
> @foo = ...;
>
> testsub(*foo);
>
> sub testsub {
> our ($x, @x);
> *x = $_[0];
> $x++;
> push @x, 100;
> }
>
> But this is really inadvisable. What is your motivation to do this kind
> of thing?
Many thanks it works fine now (with "print "@x", "\n";" :-)) but local
disappeared.
I pick up this example in a tutorial (it is old but it exists and there are
many examples
and most of them are understandable (imho)) because I searched some example of
scripts
which used local. I encounter some problems to figure out local ;-)
for example, in perldoc -q dynamic, I found this example: (I changed it a
little...)
use warnings;
# use strict;
$var = 'global';
print " in visible ";
visible();
dynamic();
lexical();
sub visible {
print "\$var has value $var\n ";
}
sub dynamic {
local $var = 'local';
print "in dynamic ";
visible();
}
sub lexical {
my $var = 'private';
print "in lexical via visible ";
visible();
print "in lexicale \$var has value $var\n";
}
output:
in visible $var has value global
in dynamic $var has a value local
in dynamic via visible $var has value local
in lexical via visible $var has value global
in lexicale $var has value private
if I want the result:
in visible $var has value global
in dynamic $var has a value local
in dynamic via visible $var has value local
in lexical via visible $var has value local
in lexicale $var has value private
I think that I have two ways:
With local:
..........
use strict;
use vars '$var';
local $var;
.....
without local:
..........
use strict;
our $var = global;
.........
Is it correct what I said ?
tia
--
Gérard
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>