in reply to Irregular Expression??

How do I determine that the variable contains a ' in the value.
There are many ways of doing so:
if ($a =~ /'/) {....} if (index ($a, "'") >= 0) {....} if (split ($a, "'", -1) >= 2) {....} if ($a =~ y/'/'/) {....}

how would I change the value in the variable to
$a = "A\'\'Bcd"
That's not a clear question. First of all, "A\'\'Bcd" is the same string as "A''Bcd". Do you want backslashes in the resulting value? Second, do you want to change the first quote? The last quote? Quotes between "A" and "B"? All quotes? Only quotes in the second position?

Abigail

Replies are listed 'Best First'.
Re: Re: Irregular Expression??
by Red_Dragon (Beadle) on Feb 23, 2004 at 22:10 UTC
    Thank you for responding Abigail.

    The second part of the question should have asked, how do I substitute \'\' for every single ' encountered in the original value of the variable.

    R_D

Re: Re: Irregular Expression??
by mutated (Monk) on Feb 23, 2004 at 22:35 UTC
    I believe what you are actually looking for is
    $a =~ s/\'/\\\'/g;
    daN.
      Close, but I think this is actually what Red_Dragon is looking for:

      $a =~ s/\'/\\\'\\\'/g;

      Update: I was a bit too lazy on my copy job, you don't actually have to escape the '. So this will save you some keystrokes:
      $a =~ s/'/\\'\\'/g;

      -jbWare
        Assuming jbware's regex is correct (not testing it), wouldn't it be better to write:

        $a =~ s#'#\'\'#g;

        That way you aren't tracking around a bunch of backslashes? Or am I remembering wrong and s/// doesn't allow it?