From: [EMAIL PROTECTED] (Peter Scott) > In article <[EMAIL PROTECTED]>, > [EMAIL PROTECTED] (Nkuipers) writes: > >Supplying module names makes answering it easier to give a better > >answer. Idiomatically, $self usually refers to the scalar being > >blessed into a class, in other words, an object. > > Actually, it is not the scalar that is blessed into the class, but the > data that it references.
You have it both wrong. (Well kind of ... depends what does Nkuipers mean by scalar.) It's the reference that's blessed. #!perl package Foo; sub bar {print "Hello\n"} package main; $s = 5; $r = \$s; # we bless the reference bless $r, 'Foo'; # print it and call a method print "\$r=$r\n"; $r->bar(); # copy the reference to a different scalar variable $r2 = $r; # print it and call a method print "\$r2=$r2\n"; $r2->bar(); # change the VALUE $s = 10; # we can still call the method print "\$r=$r\n"; $r->bar(); # lets try to bless a non reference bless $s,'Foo'; # prints: Can't bless non-reference value at - line 2. So to sum this up. The "magic" is NOT attached to the data referenced nor to the variable itself, but to the reference. Compare this with tie() ... which attaches magic to the variable ... making it's previous contents inaccessible. Jenda=========== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ========== When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]