develooper Front page | perl.perl5.porters | Postings from February 2016

[perl #127552] No warning or error on @$

Thread Previous | Thread Next
Ed Avis via RT
February 16, 2016 15:40
[perl #127552] No warning or error on @$
Message ID:
I understand that perl special variables like $! are accessible from all packages and do not need to be declared first.  That is not the issue here.  The question is which special variables exist in the first place.

I was surprised to find that a special variable @$ exists, and produces no error or warning on use, despite not being mentioned in perlvar.  That manual page does say that all variable names consisting of a sequence of digits, or a single punctuation character, are reserved for special uses.  It then lists the special uses of punctuation variables which currently exist.  I had expected that if a punctuation variable was not mentioned in that list, then it would not exist and attempting to use it would be an error.  Instead, the current implementation is that all possible single-character variables do exist, and those not mentioned in perlvar have the normal semantics of arrays or hashes.  (For scalars, all single-character variables are mentioned.)

I think that if this is considered the documented behaviour then it is less than ideal because firstly, it makes typos such as @$ for $@ hard to spot, and secondly it makes it impossible to add new special single-character array or hash variables in future.

But actually, in my opinion perlvar doesn't make it clear one way or the other.  It says the variable names are reserved (which normally indicates that you shouldn't use it for ordinary uses) but when one is not mentioned in the list of special variables, doesn't say what the semantics of it are.

So there are two options here:

Either - Disallow the use of single-character punctuation variables which aren't documented.  Since there may be current code using them, it should be done with a deprecation cycle.

Or - Document in perlvar the remaining single-character punctuation variables not currently mentioned, saying that they have the ordinary array and hash semantics (but of course the names are accessible in all packages and do not need declaring).  I think this would be an unhappy choice for the reasons given above.  But at least it would clarify things.

via perlbug:  queue: perl5 status: open

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About