in reply to Is there a better way of dealing with !~ and "Useless use of not in void context at" warnings?

You should use =~, not !~.

But in general, you can get rid of "Useless use of...in void context" by giving a non-void context. The easiest way to do this is

scalar( $str !~ s/junk//g );
In 5.6.0 and earlier, this didn't work, but I think this did:
1 if $str !~ s/junk//g;
(The constants 0 and 1 are exempt from the "Useless use" warning.)
  • Comment on Re: Is there a better way of dealing with !~ and "Useless use of not in void context at" warnings?
  • Select or Download Code