in reply to Make hash key an alias
use Lexical::Alias; my ($s, %h); alias $h{key}, $s; print \$s, "\n", \$h{key}, "\n"; => SCALAR(0x811e2f4) SCALAR(0x811e2f4)
Don't use $a and $b for variable names. They have special meanings.
Update(s): To make it clear once and for all: the code above makes the lexical scalar variable $s an alias for $h{key}. The syntax is alias <src>, <dst>. This confuses many people, because it's different from common functions like push @ary, ... or index $str, ... etc. where object comes first. Here's a paragraph from the POD:
Version 0.04 introduced the $Lexical::Alias::SWAP variable. When it is true, the arguments to the aliasing functions are expected in reverse order; that is, the alias comes first, and the source variable second.(Thanks to Jenda from perlmonks.org for requesting this.)
I don't recommend using SWAP though, it induces more unmaintainability and confusion.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Make hash key an alias
by demerphq (Chancellor) on Nov 18, 2003 at 15:38 UTC | |
by calin (Deacon) on Nov 18, 2003 at 16:31 UTC | |
by demerphq (Chancellor) on Nov 18, 2003 at 16:34 UTC |