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        


In reply to Re^2: substituting a regular expression in a file (\\) by tye
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.