In reading about Perl 6, I see a feature being trumpeted about, where you no longer have to do:
return "0 but true";
...but can instead do:
return 0 but True;
If that's the case, how does truth work in Perl 6? In Perl 5, it was pretty simple: 0, "", and undef are false, everything else is true.
What are the rules in Perl 6 when it comes to boolean context?
Perl 6 evaluates truth now by asking the object a question instead of looking at its value. The value is not the object. It's something I've liked about other object languages and will be glad to have in Perl: I get to decide how the object responds and can mutate that. As ysth said, you could do that in Perl 5 with overload, but I always feel like I have to wash my hands after doing it that way. :)
If you don't do anything to change that, Perl 6 behaves in the same way as Perl 5 so you get the least amount of surprise.
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