XP is just a number | |
PerlMonks |
Re^2: Autoboxing ... "Yes We Can" ( or how I learned to love TIMTOWTDI ;)by LanX (Saint) |
on Dec 16, 2013 at 12:33 UTC ( [id://1067324]=note: print w/replies, xml ) | Need Help?? |
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")
backgroundFor 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 Section
Meditations
|
|