Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: Replacing single quotes to two single quotes inside map

by duff (Parson)
on Nov 10, 2017 at 21:22 UTC ( #1203140=note: print w/replies, xml ) Need Help??

in reply to Replacing single quotes to two single quotes inside map

Assuming you don't mind changing $data->{$_} directly (rather than making a copy) ...

my $sql = exec_select( "call store_proc(" . join(',', ('?') x @allparm +s ) . ")", map { $data->{$_} =~ s/'/''/g; $data->{ $_ } | +| '' } @allparms );

Replies are listed 'Best First'.
Re^2: Replacing single quotes to two single quotes inside map
by Anonymous Monk on Nov 10, 2017 at 21:24 UTC
    Could you explain the pros and cons about changing $data->{$_} rather than making a copy of it?

      The pros/cons are mostly about whether or not you need the original values of $data->{$_} elsewhere since the substitution operation will change the value in-place. If you require the original value prior to the change elsewhere in your code, then clearly you don't want to change them. tybalt89 gave a similar version where the value is returned and not changed, but it requires a relatively recent perl (>= 5.14). I didn't notice if you mentioned a perl version, but some unfortunate people are still on 5.10.1 and such.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1203140]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2018-06-21 03:36 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (117 votes). Check out past polls.