Hi again,
 
I am back with a test case in attachment
in the zip file you have:
* reprod.pl : the script. I need to get the line number for every line ( in 
fact that I filter with a regexp in the original script )
* TestObjMgr2.log: the data file read by reprod.pl
you will see that line 3,5,7,9 etc are empty lines but I need to count them
 
when you run the script, you will see that line 3.5.7,9 etc are not read ( 
skipped )
 
I tried:
* open the file in ":raw" mode   => no success
* set $/ = '\0'    => no success
* reading the file and "reset" the line separator is not a good options, 
because I can handle thousands of
files with 800 000 lines each....
* having \x0d\x0d\n or \x0d\n does not make a difference.
 
If you debug the script, you will see that the line 3,5,7 etc are ignored and  
not read 
 
Ideas ?
 
Thanks
 
Eric

        -----Original Message----- 
        From: $Bill Luebkert [mailto:[EMAIL PROTECTED] 
        Sent: Thu 6/23/2005 11:25 AM 
        To: ericv 
        Cc: [email protected] 
        Subject: Re: counting lines in a text files
        
        

        Eric Vercelletto wrote:
        
        > Hi folks,
        >
        > although the answer seems simple, I have a strange phenomenon while 
reading
        > a text file, where I want to identify each
        > line by its linenumber
        >
        > obviously first reflex is to use $.
        > or at each iteration of foreach $line ( <MYFILE>)
        >       $linenumber++ ;
        >
        > this work in the majority of the lines
        >
        > but it seems some lines are not read by the foreach , and I suspect 
them to
        > be lines only containing a \n
        > I have also seen lines ending with \x0d\n but this does not seem to 
count
        > for 2 lines though
        >
        > I will provide a test case during the day, but does anyone have an 
idea of
        > what can happen ?
        
        Should work fine.
        Try reading the file and removing any \r or \n's from each line.
        Then append a \n and write it back out to another file or console
        with the line number prefixed for comparison to what the orig file
        thinks is a line.  (\n should expand to a \r\n in text mode).
        
        If you don't figure it out, post a short 10 line or whatever script
        with a hunk of data that duplicates the problem.
        
        
        --
          ,-/-  __      _  _         $Bill Luebkert    Mailto:[EMAIL PROTECTED]
         (_/   /  )    // //       DBE Collectibles    Mailto:[EMAIL PROTECTED]
          / ) /--<  o // //      Castle of Medieval Myth & Magic 
http://www.todbe.com/
        -/-' /___/_<_</_</_    http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
        


_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to