Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Aliasing values, not variables

by calin (Deacon)
on Jul 18, 2004 at 18:31 UTC ( [id://375410]=note: print w/replies, xml ) Need Help??


in reply to Aliasing values, not variables

Lexical::Alias is not suited for this task. Try Array::RefElem instead:

use Array::RefElem 'av_store'; my @array; av_store @array, 1, $array[0]; $array[1] = 2; print "@array";

If you're bent on using Lexical::Alias, you can try the following trick for your particular situation, though it's of little use for generic array element aliasing. It's an answer to the first question from How's your Perl?, adapted to Lexical::Alias.

use Lexical::Alias 'alias_a'; my @array; { my $t; alias_a @{sub {\@_}->($t, $t)}, @array; }

Warning: code untested!. I don't have my laptop which has my custom Perl install with Lexical::Alias and Array::RefElem. Particularly the second example might not work as advertised.

update: a monk confirms that code works on CB

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://375410]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-25 04:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found