defined-or (or //) is not about speed: it is about logic and concise programming: it improves legibility and maintainability. I use the feature since perl-5.8.0 and it has been a very good reason to upgrade all my perl installations, even with customer sites. I cannot think of writing any perl script that does not use this feature. Silently I still wish the low-precedence keyword err (or dor given a bikeshed argument) will return one happy day.
Now imagine writing this with ternary:
my $file = $options{file} // $options{input_file} // get_default_option (""file") // get_default_option ("input_file") + // file_exists ("$ENV{WORK_DIR}/file.in") // file_exists ("$ENV{HOME}/project_in.file") or die;
Or, preventing warnings
printf "%-20s: %s\n", $_, $options{$_} // "<undef>" for keys %options; function (map { $_ // "default" } @values); my @sorted = sort { ($a->{order} // 0) <=> ($b->{order} // 0) } @aoh;
In reply to Re^2: Make $^V and "my" implicit
by Tux
in thread Make $^V and "my" implicit
by gunzip
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |