in reply to Re: Alias vs Reference
in thread Alias vs Reference
The most general ...
That method of aliasing is interesting and occasionally useful, but it is hardly "The most general".
Besides that a reference to an array of aliases is hardly as convenient as a typeglob aliased array, it is also a very fragile structure.
As soon you do anything that modifies the referenced array -- rather than the things aliased by its contents -- the aliases cease to be aliases.
Eg. Here I've used splice to modify the array, but push, pop, shift, unshift, assignments to $#$silly and anything else will silently break the aliasing affect resulting in two entirely separate, unconnected arrays:
#! perl -slw use strict; my @a2 = 'a'..'z'; my $silly = sub{ \@_ }->( @a2 ); splice @{ $silly }, 12, 1, 'the middle'; print "@{ $silly }"; print "@a2"; __END__ C:\test>junk a b c d e f g h i j k l the middle n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Alias vs Reference
by ikegami (Patriarch) on Jun 18, 2012 at 05:03 UTC | |
by BrowserUk (Patriarch) on Jun 18, 2012 at 05:40 UTC | |
by ikegami (Patriarch) on Sep 17, 2012 at 05:45 UTC |