thanx,
Yes I see ... but I was interested WHY when we are in nested subroutines ...
the inner-one will see the lexical var only the first time !! I mean the
REASON of this perl behaviour ! It it closer/easier to think of it that
my-vars  are visible all the time in their inner scopes (except if u are
going outside the scope of the variable itself) .. what I mean if I'm not
very clear ... it is easy to think that :

{
$var is not visible here

{
 my $var = 5;
   { { sub blah {{ sub xxx{ $var is visible here all the time, not just the
first one } } } } }
}

$var is not visible here
}


On the other hand 'our' and "use vars" make a global var which as stated
anywhere is not a good programming practice (only in some special cases,
this is not one of them I think :")   / i mean use global where U need
global use local var where u need local/ ).   {note : not local-op }
So I'm using ASP.pm which compiles all scripts into one package (by
default).... so the purpose of  lexical-scope split&conquer  is no more
valid... I mean that the variable 'say $ID into script blah.pl I want to be
differnt from the $ID var into xxx.pl.... i.e. I don't want this :

package AllCompiledScripts;

our $ID;

sub compiled_blah {
  $ID =15;#or if u like our $ID = 15
    sub inner_blah{   };
};

sub compiled_xxx {
  $ID =555
    sub inner_xxx{   };
};
1;

I want this :

package AllCompiledScrips;

compiled_blah ::  $ID is not visible here
compiled_xxx ::  $ID is not visible here

sub compiled_blah {
  my $ID =15
    sub inner_blah{ compiled_blah ::  $ID visible here but compiled_xxx ::
$ID not visible  };
};

sub compiled_xxx {
  my $ID =555
    sub inner_xxx{ compiled_xxx ::  $ID visible here  but compiled_blah ::
$ID not visible };
};

compiled_blah ::  $ID is not visible here
compiled_xxx ::  $ID is not visible here

1;


So what is the REASON for this copy-on-first-call behaviour.(there have to
be some reason, if i'm not totaly dull to see it )

Thanx alot for your attention
=====
iVAN
[EMAIL PROTECTED]
=====


> > r>I have the following situation... it is not big issue but
> > r>i'm interested why this happen...
> > r>
> > r>    my $ID = 555;
> > r>    sub blah {
> > r>        ...
> > r>        $ID =  selectrow query;
> > r>        ...
> > r>    }
> >
> > This is, in fact, a big issue. You should see a message in your error
log
> > "shared variable $ID will not stay shared." You should not use a my
> > variable defined at the top level of your Apache::Registry script in a
> > subroutine. See this entry in the mod_perl guide:
> >
> >
http://perl.apache.org/guide/perl.html#my_Scoped_Variable_in_Nested_S
> >
> > The workaround is to make $ID a package global (use vars qw($ID)).
>
> With Perl 5.6, the following are roughly equivalent:
>
>   use vars qw($ID);
>
>   our $ID;
>
> However, you will need to put the `our' declaration within the block
(which
> may happen implicitely with Apache::Registry).
>
> So (pre-5.6):
>
>   use vars qw($ID);
>
>   sub foo {
>       $ID = shift;
>   }
>
> But (>= 5.6):
>
>   sub foo {
>       our $ID = shift;
> }

Reply via email to