|There's more than one way to do things|
Re: Is there an andand for Perl like there is in Ruby?by Aristotle (Chancellor)
|on Jan 08, 2009 at 09:02 UTC||Need Help??|
You can almost do this in Perl, but it requires sticking a method in UNIVERSAL (awful) and loading autobox::Core (because by default not everything is an object), both of which highly intrusive changes.
However, even with autobox loaded you cannot call methods on undef. So for all the intrusion you accepted for this it will still fail. You just have to be explicit:
You can try to abstract this out a little, but then you get either a different kind of verbosity:
Or if you try to fix that it reads in the wrong order:
And don’t even think of “fixing” this with Filter::Simple. If source filters are the answer then you’re asking the wrong question. You will have mysterious bugs if you go down that route because source filters always break. How badly depends on filter in question; yours is a case where the type of breakage is bad.
What might (eventually) be possible is to implement something like this with Devel::Declare voodoo, which is (becoming) a macro system and therefore not prone to the problems of source filters.
Makeshifts last the longest.