停止perl超载或打印内存的“地址".参考 [英] Stop perl overloading or print memory "address" of reference
本文介绍了停止perl超载或打印内存的“地址".参考的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个创建的类,该类重载了""
运算符,以打印出用户可读的对象的字符串形式.
I have a class I created that overloads the ""
operator to print out a nice stringified form of the object that is user-readable.
但是现在,我想实际获得内存地址,例如:
But now, I'd like to actually get the memory address such as:
Some_class=HASH(0xb0aff98)
如果我还没有覆盖""
运算符,通常我会使用print "$some_object"
来完成.
which is what I would have normally done by using print "$some_object"
if I had not already overridden the ""
operator.
是否有某种方法绕过重写的方法,或者失败了,仅获取该对象的内存地址?
Is there someway to bypass the overridden method or, failing that, just get the memory address of this object?
推荐答案
使用 overload::StrVal($o)
.
use overload '""' => sub { "Hello, World!" };
my $o = bless({});
print($o, "\n"); # Hello, World!
print(overload::StrVal($o), "\n"); # main=HASH(0x62d038)
这篇关于停止perl超载或打印内存的“地址".参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文