从
perldoc -f bless:
bless REF,CLASSNAME
This function tells the thingy referenced by
REF
that it is now
an object in theCLASSNAME
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",refaddr $x;
输出:
My : 237356 HASH : 237356