作者TONICOM (TONICOM)
看板Perl
标题Re: [问题] 关於subroutine reference的问题
时间Fri Oct 8 17:48:56 2010
※ 引述《TONICOM (TONICOM)》之铭言:
: 以下是个范例程式 , 请教一下各位高手们 , 为甚麽执行的结果都是 :
: Undefined subroutine &main::CODE(0x241da2c) called at test2.pl line 8
: 范例如下 :
: $ref -> { \&abc } = "123" ;
: ($sub, $para ) = each( %$ref ) ;
: $sub -> ( $para ) ;
: sub abc{
: print @_, "\n" ;
: }
: 感谢各位的帮忙 ...
不好意思 , 我刚刚翻了一下Perl doc 发现是我自己乌龙 , 以下是这个问题的解答 :
You may not (usefully) use a reference as the key to a hash.
It will be converted into a string:
$x{ \$a } = $a;
If you try to dereference the key, it won't do a hard dereference, and you won't accomplish what you're attempting.
You might want to do something more like
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 219.87.80.75