Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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(...));
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.

In reply to Indirect Object Syntax by Bod

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2022-05-26 13:48 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (93 votes). Check out past polls.