On Mon, 24 Jan 2000 18:00:01 +1300, Christian Soeller wrote:
>I would like to set named 'my' variables by a sub routine, i.e.
>something like
>
> sub foo {
> setargs('a','cdef');
> print $a+$cdef;
> }
>
>being equivalent to
> sub foo {
> my ($a,$cdef) = @_;
> print $a+$cdef;
> }
>
>In other words, is there some straightforward way to create a named
>lexical variable via XS that can then be accessed at the perl level?
Lexical variables must be declared at compile time--it is essential
for what they do and how they work. Creating them dynamically makes
very little sense, because, because, that's what dynamic variables are
there for. :-)
Now, if you meant setargs() as being in effect like a BEGIN block
(i.e. runs at compile time) that would make more sense, but still not
enough sense to be worth it. Consider this:
sub foo {
use lexicals qw($a @cdef);
print $a+@cdef;
}
The stuff inside qw() can't be dynamic, because it gets run at compile
time, when the body of foo() is being compiled; therefore foo()'s
arguments can't be used there. So it has little advantage over spelling
it my($a,@cdef).
If you're interested in dynamic variables but don't want their globalness
(i.e. you want to limit their visibility to the lexical scope), I suspect
what you're really wishing for are lexically-scoped symbol tables. See
the p5p archives for more on that.
Sarathy
[EMAIL PROTECTED]