我如何在Perl中解开一个对象?

前端之家收集整理的这篇文章主要介绍了我如何在Perl中解开一个对象?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
perldoc -f bless

bless REF,CLASSNAME@H_502_6@

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

有没有办法获得一个没有不必要的复制结构?@H_502_6@

解决方法

Data::Structure::Util

unbless($ref)@H_502_6@

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

#!/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",refaddr $x;

输出:@H_502_6@

My : 237356
HASH : 237356

猜你在找的Perl相关文章