in reply to command line replace incorrectly indexes $.

I cannot reproduce your results on ActivePerl for Windows. Are you sure each "orgtext" is on a different line? $. is the current input line number, not the number of substitutions performed.

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

Perhaps you want

perl -pi -e 's/orgtext/++$x/eg;' *.html

a.htmlb.html
After
1 2 3 4
5 6 7 8

or

perl -pi -e 's/orgtext/++$x/eg; $x=0 if eof(ARGV)' *.html

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

Update: Compacted node by replacing lists with tables.

Replies are listed 'Best First'.
Re^2: command line replace incorrectly indexes $.
by Anonymous Monk on Oct 18, 2007 at 00:26 UTC
    Hmm. I am running perl, v5.8.8 built for i486-linux-gnu-thread-multi.

    The result I want is:

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



    But the result I get is:

    a.htmlb.html
    After
    1 
    1
    2
    3
    
    1
    1
    2
    3
    

      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?

        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