Perl has - thanks to sigils - the distinction to many other languages ¹ of separated namespaces for functions, arrays, hashes and scalars
This means for instance: if we want to pass an @arr to a function we need to explicitly reference it \@arr and inside the function we always need to explicitly dereference it. ³
But what do we really gain from separated namespaces if it's considered bad style to reuse the same symbol for different types? ( %INC and @INC being an exception to the rule... but still confusing)
Would it be feasible and if yes to what cost
The former is trickier, let me explain
A simple POC implementation with plugable keywords / keyword simple would introduce new keywords like
# form 1 mine @arr = (1,2,3); # ==> my $arr = \@arr; # form 2 (optional, and more difficult to implement) mine $arr = [1,2,3]; # ==> my \@arr = $arr; # same according to ours and other datatypes
But this is not "aliasing"
consider
mine @arr = (1,2,3); # and later accidentally $arr = [4,5,6]; # ==> \@arr != $arr
this would lead to ugly bugs because both variants would point to different arrays.
The only way to solve this with pure Perl is either to make
mine $arr = [1,2,3]; # and later accidentally $arr = [4,5,6]; # ==> \@arr != $arr # even worse $arr = { a=> 1 } # ==> @arr must be detroyed? or what?
Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery
°) Excuse my lack poetic skills to come up with better names, these temporary names are still better than xmy and xour ... Feel free to suggest better...
¹) In other languages, like JS it's perfectly possible to accidentally overwrite a function-ref with a variable. Everything is a scalar, either a primitive type or a object-ref, and de-referencing happens implicitly.
²) Or even better a new lexical pragma to change my and our to act that way
³) or apply the new feature to do an explicit \@arr = $arr
|
|---|