How do I concatenate arrays of aliases in Perl? -
how concatenate arrays of aliases in perl such resulting array contains aliases?
the solution came is:
my ($x, $y, $z) = 1 .. 3; $a1 = sub {\@_}->($x); $a2 = sub {\@_}->($y, $z); $a3 = sub {\@_}->(@$a1, @$a2); "@$a3"; # 1 2 3 $_++ $x, $y, $z; "@$a3"; # 2 3 4
what not crazy create $a3
have unpack $a1
, $a2
. short arrays isn't problem, data grows larger, means array operations on aliased arrays o(n)
, including traditionally o(1)
operations push
or unshift
.
data::alias
help, doesn't work latest versions of perl. array::refelem
contains wrappers around api primitives av_store
, av_push
can used implement functionality. work:
sub alias_push (\@@) { if (eval {require array::refelem}) { &array::refelem::av_push($_[0], $_) @_[1 .. $#_] } else { $_[0] = sub {\@_}->(@{$_[0]}, @_[1 .. $#_]) } }
i interested know if there other ways. particularly if there other ways using core modules.
is 1 of cases might want linked list in perl? steve lembark has talk various cases people should reconsider rolling , unrolling arrays.
i'm curious why have things way though. not suspect odd; i'm curious problem.
Comments
Post a Comment