in reply to Re^2: command line replace incorrectly indexes $.
in thread command line replace incorrectly indexes $.

I've already explained why your code produces the a.html you're seeing.

Your code should not produce the b.html you are seeing unless you are wrong about your input, you are wrong about your code, you are wrong about your output, or your Perl is broken.

I've already shown the code that will get you what you want, so what you are asking now?

  • Comment on Re^3: command line replace incorrectly indexes $.

Replies are listed 'Best First'.
Re^4: command line replace incorrectly indexes $.
by cmarcum (Initiate) on Oct 18, 2007 at 00:48 UTC
    I'm sorry. I thought I was still logged in before. There was a typo in my last response: The result I want is:

    a.htmlb.html
    Before
    orgtext orgtext 
    orgtext
    orgtext
    orgtext
    
    orgtext orgtext
    orgtext
    orgtext
    orgtext
    
    After
    1 1
    2
    3
    4
    
    1 1
    2
    3
    4
    

      There's so many inconsistencies in your posts! You showed newlines occasionally being added, the counter magically reseting for the second file, and different behaviours for the same code. The latest is a requirement you didn't even mention initially. If anything, you asked for the opposite.

      The following code replaces the string with the line number. The close resets the counter for every file on the command line.

      perl -pi -e 's/orgtext/$./eg; close(ARGV) if eof(ARGV)' *.html