Re: local() on elements of lexical aggregates??? [OT]

2003-02-20 Thread Paul
> > Er? Sorry, I don't mean for this to sound as bad as it does,
> > but have you read the docs that *come* with Perl
> 
> i will let you take a guess.

Hmm...that sounded even worse than I thought it would.
Again, a serious apology. I *really* didn't mean for it to, lol

The discussion is offline now, but the apology deserved public airing.
:)

Paul

__
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: local() on elements of lexical aggregates??? [OT]

2003-02-19 Thread David Zhuo
On Wednesday 19 February 2003 08:16, Paul wrote:

>
> Er? Sorry, I don't mean for this to sound as bad as it does, but
> have you read the docs that *come* with Perl

i will let you take a guess.

>
> Perhaps a mistaken assumption. Could someone delineate the difference
> between package variable value and the symbol table? I thought the
> symbol table was also use to store the actual values
>

yes but probably not the value that you expect. for example:

[xx@panda] perl -e '$yy=1; print "$_\n" for(keys %::)' | grep yy
yy
[xx@panda] perl -e '$yy=1; print "$_\n" for(values %::)' | grep yy
*main::yy

>
> Mistermed, then. I'm ignorant here, and trying to cure that. Point me
> to the stack docs?
>

sure. checkout perl hack at:

http://www.perldoc.com/perl5.8.0/pod/perlhack.html#Stacks

you should read argument stack, mark stack and the save stack. in particular, 
you don't want to miss save stack since it tells you how Perl inplements 
'local $x' via the save stack.

i will answer (or i will try to) your other questions offline.

david

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: local() on elements of lexical aggregates??? [OT]

2003-02-19 Thread Paul
> >> there is no package variables in Perl, only global or lexical.
> > 
> > Not so -- ALL package variables in Perl *are* global, but likewise
> > all global variables in Perl are package vars. Even $_ is
> > technically $main::_ so that
> > 
> >   $_ = 'foo';
> >   package bob;
> >   print $main::_."\n";
> > 
> > prints "foo" and the newline.
> 
> you are inventing the phrase "package variable" but i wont' argue
> with.

Er? Sorry, I don't mean for this to sound as bad as it does, but
have you read the docs that *come* with Perl

> > What stack? Not the function call stack.
> > You mean there's a stack for symbol table entries?
> > NOW we're getting somewhere! That makes sense, and I hope it's
> > true.
> 
> why are you keep bring on the topic of symbol table with local? what
> makes you think symbol table has anything to do with the following
> statement:
> 
> my @x = (1..5);
> { local $x[0] = -1; }

Perhaps a mistaken assumption. Could someone delineate the difference
between package variable value and the symbol table? I thought the
symbol table was also use to store the actual values

> your original question is "how can local localize $x[0] given that @x
> isn't in the symbol table?"

Yep, though I understand that it may be an invalid question.
I'd still like to have it cleared up if it is.

> i am telling you that you should forget about symbol table, package 
> vairable(which you invent because all Perl knows is global and lex. 
> variable), scretchpades and/or trying to show how how many ways(there
> are virtually endless ways, i can tell you that much right now) you
> can access a variable prefixing it with it's package name.

Zillions, lol -- but please don't get testy. We all have things to
learn -- such as what "package variable" means, for you, and how the
symbol table relates, for me.

> the reason why Perl can localize $x[0] even @x is a lexical variable
> is becasue when Perl enters a block and sees the 'local $x[0]'
> statement, it puts this tmp value in the stack (not the function
> stack and there is no symbol stable entries stack), 
> it's a run time stack where Perl keeps track of all the local
> variables. 

Mistermed, then. I'm ignorant here, and trying to cure that. Point me
to the stack docs?

> all statements inside this block, therefore, see the localized
> version. 

But if you say:

 use strict;
 our $x = 1;
 { print $::x;
   my $x = 2;
   local $::x = 3;
   print $x,$main::x; 
 }
 print $::x;

you get 1231, because our $x is $main::x, which is a variable in the
main:: package, but my $x is *not* in *any* package.

My question is how those facts relate under aggregates like arrays,
where local can address subelements, even though it can't localize the
lexical itself. Try running this:

  my @x;
  local @x;

It dies. So why can I do this?

  my @x;
  local $x[0];

Because that work.

> when the block exit, the stack is destoried so the localized value
> goes away and the original value is restored.

Which doesn't explain why I can say 
  my @x;
  local $x[0];
but not
  my @x;
  local @x;

As mentioned before, though, this is rather technical for a beginner's
list. I'm still willing to discuss it, but let's take it offline, shall
we? :)

Paul


__
Do you Yahoo!?
Yahoo! Shopping - Send Flowers for Valentine's Day
http://shopping.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]