Home
Reading
Searching
Subscribe
Sponsors
Statistics
Posting
Contact
Spam
Lists
Links
About
Hosting
Filtering
Features Download
Marketing
Archives
FAQ
Blog
 
Gmane
From: Reini Urban <rurban <at> x-ray.at>
Subject: proposal on defined and exists
Newsgroups: gmane.comp.lang.perl.perl5.porters
Date: Thursday 16th February 2012 20:28:42 UTC (over 5 years ago)
I think we should adopt `exists` for checking existance of global, lexical
and
local symbols - more than just "variables" - and all types with
non-autovivification
of symbols.
This would clean up the difficulties with defined and help in the case of
autovivification and lexicals. Think of lexical gensym's.
It is also misleading that even the core testsuite in t/op/gv.t tests
for defined() not to create the symbolic arguments.
`# test if defined() doesn't create any new symbols`

non-vivify           vififies *symbol
exists(*symbol) <==> defined *{symbol}{GLOB}   // currently nonsense
exists($scalar)  <==> defined *{symbol}{SCALAR} // currently nonsense
exists(@array)  <==> defined *{symbol}{ARRAY}
exists(%hash)  <==> defined *{symbol}{HASH}
exists(&sub)     <==> defined *{symbol}{CODE}

exists $hash{key}  = keep established meaning
exists $hash->{key}    -"-
exists $array[key] = keep established meaning with caveat for delete,
                     should be different to defined $array[key]
                     exists can be checked for deletion.
exists $array->[key]   -"-

vivification of interim hash elements in a chain stays untouched, i.e.
exists $hash{key}->{element} would still create $hash{key} unless
`no autovivification` is in effect.

This should work for lexicals and locals also:
{ my @array; exists(@array) }
{ local @arrray; exists(@array) }

magical symbols are not guaranteed to non-autovivification since
they already exist.

Note that currently even these fails:
perl -le'{no autovivification; print 1 if defined *{'xx'}{GLOB};}'
*xx is still created.
perl -le'{no autovivification; print 1 if defined *{'xx'}{SCALAR};}'
*xx is still created.

May I write a patch for this?
-- 
Reini Urban
http://cpanel.net/   http://www.perl-compiler.org/
 
CD: 3ms