"Nigel Wetters" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> On Mon, 2003-02-24 at 08:21, [EMAIL PROTECTED] wrote:
> > $data[0] = \bless( {'data1' => 'foo',
> >    'data2' => 'bar'}, 'TFB');
>
> try these two examples:
>
> $data[0] = \bless( {'data1' => 'foo', 'data2' => 'bar'}, 'TFB');
> $data[1] = bless( {'data1' => 'foo', 'data2' => 'bar'}, 'TFB');
> print $data[0] ."\n";
> print $data[1] ."\n";
>
>
> you'll see that only the second produces an object: the first produces a
> reference to the object, which must be dereferenced before you can call
> a method on it.
>
> >   $data[0]->show;     # This won't work, it sais "Can't call method
"show" on unblessed reference"
>
> This is what happens when you call a method on a reference, rather than
> the object itself.
>

You could write it as:

> >   ${ $data[0] }->show;

and it would work.

A reference IS the "object" if the scalar vairable that stores it refers to
a referent that was blessed. I put "object" in quotes because with perl the
word "object" is a very loose term.

$data[0] has a reference to a reference ( the latter reference happens to be
our object in this case ):

[EMAIL PROTECTED] wadet]$ perl
$data[0] = \bless( {'data1' => 'foo', 'data2' => 'bar'}, 'TFB');
$data[1] = bless( {'data1' => 'foo', 'data2' => 'bar'}, 'TFB');
print ${ $ data[0] } . "\n";
print ${ $ data[0] }->{data2} . "\n";
print $data[1] ."\n";
print $data[1]->{data2} . "\n";
Ctrl-D
TFB=HASH(0x804c00c)
bar
TFB=HASH(0x806427c)
bar

But now I am curious as to how that could be useful in the first place?

Todd W.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to