in reply to string manipulations with regular expressions

thnx a lot for the replies!

I realize that indeed the quote() function is what I should use!

But still, I'm very interested in my regular expression problem!
I see that monarch solution works great.!However I remember that using variables like $1, $2 will not really improve performance (I'm talking about many of thousands of insertes...... and I like one-liners :)
Is there no way we can fix what I've tried so far ?

LuCa
  • Comment on Re: string manipulations with regular expressions

Replies are listed 'Best First'.
Re^2: string manipulations with regular expressions
by wfsp (Abbot) on Oct 17, 2006 at 10:10 UTC
    ...using variables like $1, $2 will not really improve performance...
    No the capture vars ($1, $2 etc.) aren't the culprits.

    From perlretut:

    If you use them, perl will set $` to the part of the string before the match, will set $& to the part of the string that matched, and will set $' to the part of the string after the match.
    ...
    It is important to note that using $` and $' slows down regexp matching quite a bit, and $& slows it down to a lesser extent...
    So $1 and friends won't effect performance.
Re^2: string manipulations with regular expressions
by monarch (Priest) on Oct 17, 2006 at 10:20 UTC
    Try this:
    $values = "'abc', 'dec'f', ''ghc''" ; $values =~ s/ (?<!\A) # no beginning-of-string in front (?<!,\s) # no comma and space in front \' # quote (?!,\s|\z) # no command and space or end-of-string ahead / \\\' # replace with \' /xg;
    It results in:
    'abc', 'dec\'f', '\'ghc\''
    I don't believe it is possible to remove the commas between words at the same time as quoting the strings.