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.)
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/^(command\.package)=(\S+)/"\$1=$version"/gei' + $ENV{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.system('rsh', $sdpType, qq[perl -pi -e 's/(?<=^\Qcommand.package=\E)\S+/$version/i' $EN +V{JBOSS_HOME}/install/version.properties]);
(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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |