Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

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
    [ELISHEVA]: I may have to resort to SOPW - but was hoping that this would be something simple
    [erix]: I'd just remove the BOM, it is pretty simple
    [ELISHEVA]: Simple yes. and I did consider that. but this isn't one off . An important data source that I don't control is generating bom prefixed utf8 files and I'd rather not have to be munging files every few months.
    [erix]: on teh other hand a SOPW is pretty much garanteed to get an answer from tux (and probably the module fixed)
    [ELISHEVA]: plus it bugs me that something that *should* be simple, *should* work- unicode and noms aren't exactly the new kids on the block
    [ELISHEVA]: well then since the obvious possible mistakes on my part have been ruled out, SOPW it is.
    [ELISHEVA]: the data source, or one of them, is the OECD - they provide a *lot* of data that ought to be easily available to perl programmers.
    [erix]: it might be cunning to mention the module in the title... :)
    [ELISHEVA]: fancy that - a title that actually describes the problem :-)
    [ELISHEVA]: but actually thanks for the reminder

    How do I use this? | Other CB clients
    Other Users?
    Others romping around the Monastery: (8)
    As of 2017-05-28 20:34 GMT
    Find Nodes?
      Voting Booth?