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:
Now I can write:my $default = 0; my $input_number = $ARGV[0]; my $number = defined $input_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 $number = $input_number // $default;
With defined-or operator, can I simply writemy $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';
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?my $theme = ( ( $global_config->{modes}{$current_mode}{theme} // $theme_config->{current_theme} ) // $default_theme ) // 'none';
Thanks all for sharing your experiences.
Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Sequential defined-or operators
by ikegami (Patriarch) on Jan 14, 2008 at 06:04 UTC | |
by WoodyWeaver (Monk) on Jan 14, 2008 at 16:44 UTC | |
by naikonta (Curate) on Jan 16, 2008 at 17:05 UTC | |
by naikonta (Curate) on Jan 14, 2008 at 09:38 UTC | |
by ikegami (Patriarch) on Jan 14, 2008 at 12:18 UTC | |
by naikonta (Curate) on Jan 16, 2008 at 16:54 UTC | |
Re: Sequential defined-or operators
by Tux (Canon) on Jan 14, 2008 at 08:20 UTC | |
by naikonta (Curate) on Jan 14, 2008 at 09:49 UTC | |
Re: Sequential defined-or operators
by Util (Priest) on Jan 14, 2008 at 22:21 UTC | |
by plobsing (Friar) on Jan 15, 2008 at 02:39 UTC | |
by ikegami (Patriarch) on Jan 15, 2008 at 03:28 UTC |
Back to
Seekers of Perl Wisdom