perl - 如何在 Perl 中取消祝福对象?

标签 perl oop bless

来自 perldoc -f bless :

bless REF,CLASSNAME

This function tells the thingy referenced by REF that it is now
an object in the CLASSNAME package.



有没有办法在没有不必要的复制的情况下获得无福的结构?

最佳答案

Data::Structure::Util

unbless($ref)

Remove the blessing from any objects found within the passed data structure.


#!/usr/bin/perl

use strict; use warnings;

use Scalar::Util qw( refaddr );
use Data::Structure::Util qw( unbless );

my $x = bless { a => 1, b => 2 } => 'My';

printf "%s : %s\n", ref $x, refaddr $x;

unbless $x;

printf "%s : %s\n", ref $x, refaddr $x;

输出:

我的:237356
哈希:237356

关于perl - 如何在 Perl 中取消祝福对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2329385/

相关文章:

perl - 如何在mod_perl2下的startup.pl中学习DOCUMENT_ROOT?

javascript - 面向对象的 Javascript : event handling

Python类变量更新

perl - 我怎样才能在 Perl 中祝福一个字符串?

Perl:如何深度复制受祝福的对象?

regex - Perl:从文件中间读取时如何避免正则表达式 UTF-8 错误

perl - 使用 perl 的自签名证书通过 https 访问 xenapi

perl - 如何使用 Perl 在 SFTP(版本 3)中将传输模式设置为 ASCII

java - 如何强制java对象以特定顺序实例化它的实例变量?

perl 在脚本和 PerlCritic 中使用 bless self