in reply to Re^2: Replacing single quotes to two single quotes inside map
in thread Replacing single quotes to two single quotes inside map

Hi and I hope you can see this again!
I got it to work, my Perl version is v5.10.1, but I am getting a warning message as this:

Useless use of a constant in void context at... that's from the line where the call is.

I am actually replacing MSWord quote with a regular quote since the DB can't handle it, but if I pass a normal single quote using place holders, it works. This how my code looks like now:
my @allparms = qw( letters loc type name zip); my $sql = exec_select( "call store_proc(" . join(',', ('?') x @allparm +s ) . ")", map { (my $dx = $data->{ $_ }) =~ s/’/'/g || '' ; $dx; } @ +allparms );
How could a prevent this warning and why is it happening ?
Thanks for looking!

Replies are listed 'Best First'.
Re^4: Replacing single quotes to two single quotes inside map
by choroba (Cardinal) on Nov 14, 2017 at 17:01 UTC
    That's because of the || ''. If the substitution returns false, i.e. there's no smart quote to substitute, you replace this return value that goes nowhere ("void context") by an empty string. You probably meant to add it into the assignment instead?
    map { (my $dx = $data->{ $_ } || '') =~ s/’/'/g; $dx } @allparms

    But that would replace 0's with empty strings. Use // to replace only undefs.

    Update:

    map { (my $dx = $data->{ $_ } // '') =~ s/’/'/g; $dx } @allparms
    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
      You mean that this way:
      map { (my $dx = $data->{ $_ } || '') =~ s/’/'/g; $dx } @allparms

      Will not replace 0s with empty string, correct?