The advantage of autoboxing, is not to make this easier:
my $error = 3.1415927->minus( 22->divide( 7 ) )->abs();
But rather, if I write a function that deals with $href entirely though method calls rather than the built-in keywords, and document that I have done so, then somebody calling that function is now able to pass it, instead of a hashref, a blessed object providing the same interface; i.e. polymorphism.
This can be achieved somewhat using tied variables, but the interface is very low-level - it's not easy to, say, quickly override the order a foreach loop will traverse an array.
Besides which, in the former example you are hideously breaking encapsulation by using the assignment operator! ;-)
(my $error)->set_value( 3.1415927->minus( 22->divide( 7 ) )->abs() );
In reply to Re^6: use feature 'postderef'; # Postfix Dereference Syntax is coming in 5.20
by tobyink
in thread use feature 'postderef'; # Postfix Dereference Syntax is coming in 5.20
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |