My last answer was more about the general properties of method-syntax.

But there is also a very specific Perl issue, which became clearer after playing around.

Perl has a syntactical ambiguity between scalars and one element lists.

So writing something like $ref->functionality clearly operates on the referenced elements while  functionality $ref might operate on the "listed" reference itself.

Methodcall gives us an opportunity to add new flavors of grep which operate on references without the need to rename it grepref.

Think of a hashgrep which could be written  $href->grep sub { $_->key =~ /x/ }

(the need to write sub is due to another syntactic ambiguity: "block" vs "literal hash")

background

For instance it's not trivial/possible to augment the classical

 grep BLOCK  LIST

to also mean

 grep BLOCK AREF

Because it's not possible to rule out that  grep {...} $aref means "operate on the list with the one element $aref".

Languages where "everything is an object/reference" w/o lists don't have this abiguity.

They need workarounds for lists, for instance do some JS dialects introduce list-assignments by using array syntax:

 [a,b] = [b,a] ;// swap elements Mozilla JS 1.7

Cheers Rolf

( addicted to the Perl Programming Language)


In reply to Re^2: Autoboxing ... "Yes We Can" ( or how I learned to love TIMTOWTDI ;) by LanX
in thread Autoboxing ... "Yes We Can" ( or how I learned to love TIMTOWTDI ;) by LanX

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.