is there a shorter syntax or operator for
defined $functionpointer ? $functionpointer->($value) : $value
i would like to have sth like the //
-Operator, so that I can shortly write
$functionpointer //->() $value
or anything in that direction
what I don't want to do is write an extra method, overload operators or so
No, there is none. There are discussion, though, about introducing it: What operator should p5p use for safe dereferencing at PerlMonks.
You can replace the $functionpointer
by an anonymous constant function that returns your default value like this (tested in 5.12.1):
($functionpointer // sub {$default})->(@args)
It's a little hackish, but it works. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With