Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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!

In reply to Sequential defined-or operators by naikonta

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    [hippo]: They had purchased some shiny new 486 DXs the year before but crippled them by installing Win 3.1. I demo'd Linux with X on them to the department head and got the go-ahead to wipe Windows and install the new hotness.
    [marto]: glory days ;)
    [hippo]: Too true :)

    How do I use this? | Other CB clients
    Other Users?
    Others lurking in the Monastery: (8)
    As of 2018-06-22 09:58 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (124 votes). Check out past polls.