Rule #1 of using system: avoid the shell. Unless you can't. Here is a case of both.

You can avoid the shell locally. Do so. You can't avoid the shell remotely, so we'll deal with that.

Rule #3 (I think) of regexps: avoid leaning toothpick syndrome (LTS). Too many escapes can get confusing. Change your delimiter if you have to. In your case, you're just escaping everything - no need. (Funnily enough, you missed the extra \ on "\." in "command\.package" - but by avoiding the extra shell, we shouldn't need to worry about it. As much.)

system('rsh', $sdpType, qq[perl -pi -e 's/^(command\.package)=(\S+)/"\$1=$version"/gei' + $ENV{JBOSS_HOME}/install/version.properties]);
You may still need to double what few escapes we have for the remote shell. And may need to double again for the local perl. But the $1 shouldn't need extra escaping. That said, you probably also want to simplify this just a wee bit more:
system('rsh', $sdpType, qq[perl -pi -e 's/(?<=^\Qcommand.package=\E)\S+/$version/i' $EN +V{JBOSS_HOME}/install/version.properties]);
By using a zero-width positive look-behind assertion (see perlre, we can get rid of your eval modifier. By using \Q and \E (those \'s may need doubling), we no longer worry about special characters (admittedly, there's only one - but it's a useful habit to be in). And your g modifier was never really needed since we anchored at one end anyway.

(Warning: untested code - use at own risk.)


In reply to Re: substituting a regular expression in a file by Tanktalus
in thread substituting a regular expression in a file by s_gaurav1091

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.