Tie::RefHash - 使用參考作為雜湊鍵
版本 1.40
require 5.004;
use Tie::RefHash;
tie HASHVARIABLE, 'Tie::RefHash', LIST;
tie HASHVARIABLE, 'Tie::RefHash::Nestable', LIST;
untie HASHVARIABLE;
這個模組提供使用參考作為雜湊鍵的能力,前提是您先將雜湊變數tie
到這個模組。通常,只有繫結雜湊本身的鍵會保留為參考;若要在雜湊的雜湊中使用參考作為鍵,請使用 Tie::RefHash::Nestable,它包含在 Tie::RefHash 中。
它是使用標準 perl TIEHASH 介面實作的。請參閱 perlfunc(1) 和 perltie(1) 中的tie
條目以取得更多資訊。
Nestable 版本的工作原理是尋找要儲存的雜湊參考,並將它們轉換為繫結雜湊,以便它們也可以使用參考作為鍵。當您將對自己雜湊的參考儲存在繫結雜湊中時,這將會在沒有警告的情況下發生。
use Tie::RefHash;
tie %h, 'Tie::RefHash';
$a = [];
$b = {};
$c = \*main;
$d = \"gunk";
$e = sub { 'foo' };
%h = ($a => 1, $b => 2, $c => 3, $d => 4, $e => 5);
$a->[0] = 'foo';
$b->{foo} = 'bar';
for (keys %h) {
print ref($_), "\n";
}
tie %h, 'Tie::RefHash::Nestable';
$h{$a}->{$b} = 1;
for (keys %h, keys %{$h{$a}}) {
print ref($_), "\n";
}
Tie::RefHash 使用CLONE
方法完全支援執行緒。
Storable 鉤子提供語義正確的序列化和繫結 refhash 的複製。
perl(1)、perlfunc(1)、perltie(1)
錯誤可透過 RT 錯誤追蹤器 (或 bug-Tie-RefHash@rt.cpan.org) 提交。
Gurusamy Sarathy <gsar@activestate.com>
Ed Avis <ed@membled.com> 的 Tie::RefHash::Nestable
Yuval Kogman <nothingmuch@woobling.org>
Karen Etheridge <ether@cpan.org>
Florian Ragwitz <rafl@debian.org>
Jerry D. Hedden <jdhedden@cpan.org>
本軟體的版權為 (c) 2006,所有者為 יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org>。
這是自由軟體;您可以在與 Perl 5 程式語言系統相同的條款下重新散布或修改它。