I have looked through the four or so threads where this warning is discussed and summarise that there is lack of skepticism about it. So from my point of view, all the discussions are equally lacking in skepticism and I might as well post my comment here. Here is the code snippet where I just encountered it today:-
my $suppress = ($self->{simpos} == 1) and (($typ eq 'BHC') || ($typ eq 'ISC' +));
So I want to save the truth value of the combined tests, with the expectation of using it more than once in my module. The first is a configuration value: 0 for no simulating, 1 for development simming and 2 for the expected situation in production, followed by one of two additional requirements for the need to set the "suppress" flag (which will later in the code suppress errors from an unenhanced component being delivered by someone else). I don't want to do it differently, e.g. an if or a ternary or something, because it would look more naff - Perl should not be warning me into producing worse code. So after due consideration, I opted to isolate the assignment instead of avoiding it.
my $suppress; { no warnings; $suppress = ($self->{simpos} == 1) and (($typ eq 'BHC') || ($typ eq 'ISC' +)); }
Update: my bad, spoke too soon: I needed an extra bracket around the whole assignment and the warning goes away on its own. The lack of an outer bracket indeed renders the last two tests useless, so Perl was right after all.
my $suppress = (($self->{simpos} == 1) and (($typ eq 'BHC') || ($typ eq 'ISC +' +)));

One world, one people


In reply to Re^2: Useless use of string in void context by anonymized user 468275
in thread Useless use of string in void context by RobertCraven

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.