in reply to hash o' refs

I have a question. If I have an object "foo" with a method "color" which returns a reference to a hash within foo that store's color I could use it in the following manner:

print "A foo is ".$foo->color.". Isn't that pretty?\n";
and get for example,

A foo is blue. Isn't that pretty?

But if I use:
print "A foo is $foo->color . Isn't that pretty?\n";

or if I use:

print "A foo is ${$foo->color}. Isn't that pretty\n";

Perl returns hash references literally.
I can understand why it would do that for the first item but why can't ${$foo->color} be evaluated within a string?

Replies are listed 'Best First'.
RE: RE: hash o' refs
by merlyn (Sage) on Aug 08, 2000 at 19:34 UTC
    You can't call a method as a double-quoted string interpolation. You can use a hashref or arrayref, or a simple array or hash element, or an array slice or hash slice, or a simple scalar. Isn't that enough? {grin}

    But apparently, a method call was considered too much like a full expression to be parseable, er, possible inside a double-quoted string.

    -- Randal L. Schwartz, Perl hacker