in reply to Re: substituting a regular expression in a file
in thread substituting a regular expression in a file

To check one's work, just go one step at a time.

Inside of qq[...], \. is just . and \S is just S. So rsh will get the following argument:

perl -pi -e 's/^(command.package)=(S+)/"$1=..."/gei' $ENV{JBOSS_HOME}/ +install/version.properties

which is clearly wrong.

I'd replace \. with [.] since that survives this type of situations more easily. So the remaining trick is how to get \S to the remote Perl. \\S would give \S to rsh which would give '...\S...' to the remote shell which would work.

The /e isn't need on this s/// so drop that and drop the double quotes as well:

system( 'rsh', $sdpType, q[perl -pi -e 's/^(command[.]package)=(\\S+)/$1=] . $version . q[/gi' $ENV{JBOSS_HOME}/install/version.properties] +, );

Note that qq[\\S] eq q[\\S], and I avoid using things like q[\S] since it tends to lead people into thinking that q[\\mach\share\dir\] works.

This sends the following argument to rsh:

perl -pi -e 's/^(command[.]package)=(\S+)/$1=.../gi' $ENV{JBOSS_HOME}/ +install/version.properties

which gets sent to the remote shell producing the following arguments

perl -pi -e s/^(command[.]package)=(\S+)/$1=.../gi .../install/version.properties

which should work.

Note that if $version ends up containing any single quote characters, then you are in trouble again.

Inserting the 'echo' command at different points can help you while you figure out how quoting works at the different stages:

system( 'echo', 'rsh', $sdpType, q[perl -pi -e 's/^(command[.]package)=(\\S+)/$1=] . $version . q[/gi' $ENV{JBOSS_HOME}/install/version.properties] +, ); #then system( 'rsh', $sdpType, q[echo perl -pi -e 's/^(command[.]package)=(\\S+)/$1=] . $version . q[/gi' $ENV{JBOSS_HOME}/install/version.properties] +, );

- tye