http://qs321.pair.com?node_id=11138524

Bod has asked for the wisdom of the Perl Monks concerning the following question:

Over on on another thread, I got my wrist slapped* by kcott for using Indirect Object Syntax. I have read the linked documentation and its warnings and I am not sure I totally understand. So I am hoping some wise Monks will help with clarification.

The offending code I posted was:

my @bounds = new GD::Image->stringFT($colour, "Image/outline.ttf", 90, + 0.18, 0, 0, $watermark_text);
As I read the documentation, the problem is that the Perl interpreter has difficulty knowing whether I mean:
@bounds = &new(GD::Image->stringFT(...));
or
my $gd = new GD::Image; @bounds = $gd->stringFT(...);
(&new used to make it clear it is a subroutine!)
and because Perl's interpreter could potentially get this wrong, so could any human trying to understand the code.

Is that about right???
Or is there more too it than that?


A secondary question that follows on...
The documentation says:
To parse this code, Perl uses a heuristic based on what package names it has seen, what subroutines exist in the current package, what barewords it has previously seen, and other input. Needless to say, heuristics can produce very surprising results!

Does this mean that a constant piece of code, such as a module, could behave very differently depending on context? For example, if the same module were utilised in two different scripts? And what about between different versions of Perl. Could code behave differently depending on the version of Perl?

* Just to be clear, it was a very welcome wrist slapping from kcott - I am here to learn and hopefully help others. I am always very grateful when my mistakes are pointed out as it allows me to improve my skills.