perlquestion
naikonta
Everybody seems to be happy with the presence of defined-or (//) operator in Perl 5.10, including me. As I often write:
<code>
my $default = 0;
my $input_number = $ARGV[0];
my $number = defined $input_number ? $input_number : $default;
</code>
Now I can write:
<code>
my $number = $input_number // $default;
</code>
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:
<code>
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';
</code>
With defined-or operator, can I simply write
<code>
my $theme = $global_config->{modes}{$current_mode}{theme} //
$theme_config->{current_theme} //
$default_theme //
'none';
</code>
or, should I use some parens to delimit the (inner) expressions such as,
<code>
my $theme = (
(
$global_config->{modes}{$current_mode}{theme}
//
$theme_config->{current_theme}
)
//
$default_theme
)
//
'none';
</code>
Is there any other alternative? Is this possible at all?
<p>Thanks all for sharing your experiences.
<div class="pmsig"><div class="pmsig-607636">
<hr size="1" noshade="1">
<p align="right"><small>
<i>Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!</i></small></p>
</div></div>