Re: [問題] 關於subroutine reference的問題

看板Perl作者 (TONICOM)時間14年前 (2010/10/08 17:48), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
※ 引述《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
文章代碼(AID): #1ChkaBGz (Perl)
文章代碼(AID): #1ChkaBGz (Perl)