in reply to Useless use of string in void context

The useless string in void context is actually "'$A->{genome}' not valid" (you don't do anything with it, so it has no effect, so it's useless).

This is one of the cases where line numbers are wrongly reported by perl.

Replies are listed 'Best First'.
Re^2: Useless use of string in void context
by RobertCraven (Sexton) on Jul 22, 2011 at 10:27 UTC
    Thanks, that one hurt. Is there any information out there that gives hints/explains when Perl reports wrong lines?

      This wouldn't have helped with the misleading line number reported, but might have (and might in the future) spark your thinking about just what the root problem is: use diagnostics;

Re^2: Useless use of string in void context
by anonymized user 468275 (Curate) on Feb 17, 2015 at 10:36 UTC
    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