You need a double evaluation there. The first /e puts the contents of $str_regex into the replacement, and the second /e evaluates the contents as Perl code. Notice I double quote around $str_regex: one to quote it, and one for the Perl code I'll evaluate later.

$old_db = "emdb1"; $new_db = "kuku"; $string = "AUTHORIZATION,libctl62-m.sl,CONTROLM,emdb1,b02ed6600206 +ca161d165355c67b72073b6123d6838f1f68203b78cb9c4c63c9,emdb2,,;" ; $str_regexp = '"$1$2$3$new_db,"' ; $string =~ s/([^,]*,)([^,]*,)([^,]*,)([^,]*,)/$str_regexp/ee; print "$string\n";

Also, the right hand side is just a double quoted string. It's not a regexp in any way.

Lastly, if you're manipulating anything more complex regularly, you might want to use one of the comma separated value modules on CPAN rather than doing it yourself.

Good luck :)

--
brian d foy <brian@stonehenge.com>
Subscribe to The Perl Review

In reply to Re: use qr// variable in right side of s/// operator by brian_d_foy
in thread use qr// variable in right side of s/// operator by psimonovsk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.