in reply to Re: Make $^V and "my" implicit
in thread Make $^V and "my" implicit
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;
Enjoy, Have FUN! H.Merijn
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Make $^V and "my" implicit
by boftx (Deacon) on Feb 04, 2014 at 01:13 UTC | |
by Tux (Canon) on Feb 04, 2014 at 07:21 UTC | |
by boftx (Deacon) on Feb 04, 2014 at 07:38 UTC | |
by Tux (Canon) on Feb 04, 2014 at 08:11 UTC | |
by ikegami (Patriarch) on Feb 05, 2014 at 18:29 UTC | |
Re^3: Make $^V and "my" implicit
by Anonymous Monk on Feb 04, 2014 at 00:31 UTC |
In Section
Seekers of Perl Wisdom