Ok, you have a point here, but I dont think its relevent.
Fair enough :-) I read your definition of "declare" in your original post to relate to creation. I have obviously misunderstood.
Nothing intrinsic about them "created" anything, instead a rule that is in effect in many situations besides when you use these keywords is responsibile for the autovivification. For instance any fully qualified variable name usage or subroutine declaration would have done the same thing.
True (although there is at least one place where autovivification doesn't happen.)
However, does the fact that you can create symbol tables and symbol table entries in other ways mean that they are not declarations? It seems to fit the definition you gave in your original post:
"They declare that a given object is to be created and henceforth will be reffered to by a given name"
Are packages and package globals not declared in Perl? If we changed Perl so the first occurance of a variable declared it as a lexical in the current scope would that mean that my stopped being a declaration because lexically scoped variables could be created implicitly too?
I'm just trying to figure out what exactly you mean by "declare".
A second issue is that your second example is a poor one. You arent testing for the existance of $Bar there, you are testing for the existance of any variable type with the given name.
I never said I was testing for the existance of $Bar. I said that our "creates a symbol table entry if one doesn't already exist" - and that was exactly what I was testing for :-)
I think to me it comes down to this. Using other approaches I can write a program that is identical from an introspective view to any program written with package and our declarations. However the same is not true with my , or sub (afaik).
I'm not quite sure what you mean by "an introspective view" but I don't see a way to write:
use strict; use warnings; sub foo { our $Package_global = 'foo'; }; print $Package_global;
And get an error for the non-explicitly scoped variable in the print without using our.
For me our declares a lexical variable that is automatically aliased to a package global (creating it if it doesn't already exist)... so I think of it as a declaration.
It declares a variable with weird behaviour - but it's still a variable declaration.
I would prefer that there was a better term for what my and sub do, and that "declare" meant the same thing in computereses as it does in english, but alas such is not so. And accordingly I think its dangerous to mix the terms.
Possibly, but (and this may just be me being dim - it's been a long day :-) I'm not seeing how your definition of "declare" excludes our and package.
It it to do with creating things? Is it to do with warnings on scope usage/redefinition? Is it to do with implicit vs explicit creation? Are we talking about declaration of a variable, or the declaration of the thing that the variable refers? Something else?
Update:
I think our is the only way you can apply attributes to package vars too.
our @EXPORT : unique = qw(foo);
In reply to Re^3: On Declaration
by adrianh
in thread On Declaration
by demerphq
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |