The problem with using the  || (logical-or) operator (see perlop) in this case is that the undefined value is false, as are 0, '0' and '' (the empty string), and  || does not distinguish. If your Perl version is 5.10+, you can use the  // (defined-or) operator; otherwise, you're stuck with syntax that's a bit more messy:

c:\@Work\Perl\monks>perl -wMstrict -le "use 5.010; ;; my @ra = (0, 0, 0); ;; my $i = 1; print qq{value at index $i: }, $ra[$i] || 'undef'; print qq{value at index $i: }, $ra[$i] // 'undef'; print qq{value at index $i: }, defined($ra[$i]) ? $ra[$i] : 'undef' " value at index 1: undef value at index 1: 0 value at index 1: 0


Give a man a fish:  <%-(-(-(-<


In reply to Re^3: Annoying 'Use of uninitialized value in concatenation' warning by AnomalousMonk
in thread Annoying 'Use of uninitialized value in concatenation' warning by alain_desilets

Title:
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, details, 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, summary, 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.