Re: [問題] 關於subroutine reference的問題
※ 引述《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
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
Perl 近期熱門文章
PTT數位生活區 即時熱門文章