On Mar 28, Abhishek Dave said:

i am sticking with a problem to replace all words of a file in such a =
manner that the first and second word need to interchanged.
some thing like ...

100000 100001 20000 20001 ....

so that the output file will be

100001 10000 20001 20000 ....

The easiest way I can think of is:

  s/(\S+)(\s+)(\S+)/$3$2$1/g;

That reverses every pair of fields, and retains the whitespace that was between them.

--
Jeff "japhy" Pinyan         %  How can we ever be the sold short or
RPI Acacia Brother #734     %  the cheated, we who for every service
http://japhy.perlmonk.org/  %  have long ago been overpaid?
http://www.perlmonks.org/   %    -- Meister Eckhart

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to