in reply to Unusual Behavior in Interpolative Context

Method calls aren't interpolated within double quotes. So getNodeName isn't even getting called in the second context. You can force interpolation:
print "@{ [ $root->getNodeName ] }\n";
I used to do this but then I started to think it rather ugly and started using printf and sprintf instead:
printf "%s\n", $root->getNodeName;
because I think it's prettier.

Replies are listed 'Best First'.
Re: Re: Unusual Behavior in Interpolative Context
by sierrathedog04 (Hermit) on Feb 01, 2001 at 20:00 UTC
    Thanks for explaining to me that method calls are not resolved in interpolative context.

    I came across an interesting tidbit in Chapter 8 of the Camel book that is related to your workaround: It said

    Avoid printf if print will work. Quite apart from the extra overhead of printf, some implementations have field length limitations that print gets around.
    So based on what Larry Wall says even if your way of forcing interpolation is ugly it is still preferable.
      Also remember that print takes a list of arguments. I don't find it too much of a hassle to say something like:

      print "Result: ", $obj->foo(), "\n";

      It's a little more efficient, too, but if that's the last thing you need to optimize you're way ahead of the game.