Arrow Operator Shenanigans
Out of curiosity, boredom, and some inspiration by the method abuse in Safe::Isa and Object::Remote, I tried the following:
use strict;
use warnings FATAL => 'all';
use feature 'say';
my $split = sub {
my ( $str, $sep ) = @_;
return [ split( $sep, $str ) ];
};
my $join = sub {
my( $arr, $sep ) = @_;
return join($sep,@$arr);
};
say "Lorem ipsum dolor sit amet"->$split(" ")->$join(":");
my $inc = sub {
$_[0]++;
};
my $num = 4;
$num->$inc;
$num->$inc;
say $num;
I was mildly surprised that it worked. I was more surprised that I couldn't find a reason for why it worked in the documentation for the Arrow Operator.
edit [ In the comments I was pointed to perldoc perlobj where this behavior is documented. ]
I'm certain coding this way would be a Pretty Bad Idea ( especially as an undocumented language feature ) but it has a sort of appeal; though 70% of the appeal is just the sheer hackery of it with the rest being some theory that chaining may be easier to read than g(f(x)).