http://qs321.pair.com?node_id=662262

naikonta has asked for the wisdom of the Perl Monks concerning the following question:

Everybody seems to be happy with the presence of defined-or (//) operator in Perl 5.10, including me. As I often write:
my $default = 0; my $input_number = $ARGV[0]; my $number = defined $input_number ? $input_number : $default;
Now I can write:
my $number = $input_number // $default;
Lacking of chances to download and install Perl 5.10 and test it myself (which can be read as 'lazy' :-) ), I wonder if any monks have experiences on using this one of new-long-waited-features in sequential. Take a look at this example:
my $default_theme = get_default_theme(); my $global_config = read_config('/path/to/config_file'); my $theme_config = read_config($global_config->{theme_file}); my $current_mode = get_current_mode(); my $theme = defined $global_config->{modes}{$current_mode}{theme} ? $global_config->{modes}{$current_mode}{theme} : defined $theme_config->{current_theme} ? $theme_config->{current_theme} : defined $default_theme ? $default_theme : 'none';
With defined-or operator, can I simply write
my $theme = $global_config->{modes}{$current_mode}{theme} // $theme_config->{current_theme} // $default_theme // 'none';
or, should I use some parens to delimit the (inner) expressions such as,
my $theme = ( ( $global_config->{modes}{$current_mode}{theme} // $theme_config->{current_theme} ) // $default_theme ) // 'none';
Is there any other alternative? Is this possible at all?

Thanks all for sharing your experiences.


Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!