如何获取Perl中的对象的名称? [英] How can I get name of an object in Perl?

查看:150
本文介绍了如何获取Perl中的对象的名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我创建一个对象如下:

Say I make an object as follows:

$object22=new somepackage("stuff");

以后我想运行这样的子程序:

and later I want to run a subroutine like this:

$object22->somesubroutine();

我想捕获子例程somesubroutine中的字符串object22。
我试过:

I would like to capture the string "object22" in the subroutine "somesubroutine." I tried:

$self=@_;
print $self;

但是只是给了我 somepackage = HASH(somehexnumber)

请让我知道如果这是可能的,如果是这样的代码是这样做的。

Please let me know if this is possible and if so what the code is to do so.

推荐答案

这是不可能没有可怕的黑客(通过堆栈帧)。该名称只是对对象的引用,它不是对象的一部分。

This is impossible without horrible hackery (looking through the stack frames). The name is just a reference to the object, it is not part of the object.

您以错误的方式处理问题。也许更多描述一下?

You're approaching the problem in the wrong way. Perhaps describe it more?

这篇关于如何获取Perl中的对象的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆