YAP6 Operator: The Default Operator

by Adriano Ferreira

Another article of the series "Yet Another Perl 6 Operator"

Among the new Perl 6 operators, there is the handy operator '//', known as defined-or or the default operator. This novelty was anticipated by the introduction of this syntactic bit in Perl 5 (see the upcoming 5.10 release) — so you won't need to wait for Perl 6 to start using it.

# dor.pl
use 5.010;
print "arg: '", shift // "?", "'\\n";

$ perl dor.pl one
arg: 'one'
$ perl dor.pl ""
arg: ''
$ perl dor.pl
arg: '?'


2007-12-17 16:06:53
You probably intended to write "'\n" in the print statement on the third line of your first example, rather than "'n".

Adriano Ferreira
2007-12-18 02:45:14
@TomP Now it should be fixed. The weird thing is that I correctly wrote "'\n" but MT ate the backslash. So I double it and it worked.
Ed Avis
2008-01-27 07:36:50
|| and && have corresponding low-precedence versions 'or' and 'and'. Will Perl 6 support 'dor'?