On Thu, Oct 10, 2002 at 08:27:27PM +0200, Jenda Krynicky wrote: > It's the reference that's blessed.
It's the referent that's blessed. For example: #!/usr/bin/perl -w use strict; my $s = 10; my $obj1 = \$s; bless($obj1, "Foo"); $obj1->foo(); # prints "I am foo()" my $obj2 = \$s; $obj2->foo(); # prints "I am foo()" $s = "foo"; my $obj3 = \$s; $obj3->foo(); # prints "I am foo()" package Foo; sub foo { print "I am foo()\n" } > So to sum this up. The "magic" is NOT attached to the data referenced > nor to the variable itself, but to the reference. The magic is attached to the variable referenced in the first argument in the call to bless(). bless() simply returns a reference to that variable. This can be further shown with Devel::Peek, a module for taking a look at the internals of Perl variables: #!/usr/bin/perl -w use Devel::Peek; use strict; my $s = 10; my $obj = \$s; bless($obj, "Foo"); Dump($s); This prints: SV = PVMG(0x8112ef0) at 0x8100904 REFCNT = 2 FLAGS = (PADBUSY,PADMY,OBJECT,IOK,pIOK) IV = 10 NV = 10 PV = 0 STASH = 0x80f61c0 "Foo" Notice the STASH element at the end. Michael -- Administrator www.shoebox.net Programmer, System Administrator www.gallanttech.com -- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]