ericv wrote:

>       -----Original Message----- 
>       From: $Bill Luebkert [mailto:[EMAIL PROTECTED] 
>       Sent: Fri 6/24/2005 12:25 AM 
>       To: ericv 
>       Cc: [email protected] 
>       Subject: Re: counting lines in a text files
>       
>       
> 
>       ericv wrote:
>       
>       > 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 )
>       ...
>       > If you debug the script, you will see that the line 3,5,7 etc are 
> ignored and  not read
>       > 
>       > Ideas ?
>       
>       1) I won't help if you can't get the etiquette down.  Don't top-post.
>       Intersperse your replies after the pertinent line in the prev post.
>       Remove .sigs and all info that isn't pertinent to your reply.
> 
>       >> Sorry for this. I was not aware, now I am.
>       
>       2) It works better if you actually attach the data.
>       >>  the data is now attached, sorry once again.
>       --
>         ,-/-  __      _  _         $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)

You left my .sig - always remove the previous posters .sig.

Here's a dump of your data:

000000  20 20 20 4f 52 44 45 52  20 42 59 0d 0a 20 20 20      ORDER BY..
000010  20 20 20 54 31 2e 4c 4f  43 41 4c 45 5f 43 4f 44      T1.LOCALE_COD
000020  45 0d 0d 0a 4f 62 6a 4d  67 72 53 71 6c 4c 6f 67   E...ObjMgrSqlLog
000030  09 44 65 74 61 69 6c 09  34 09 32 30 30 35 2d 30   .Detail.4.2005-0
000040  36 2d 31 38 20 31 30 3a  32 37 3a 32 32 09 42 69   6-18 10:27:22.Bi
000050  6e 64 20 76 61 72 69 61  62 6c 65 20 31 3a 20 50   nd variable 1: P
000060  54 47 0d 0d 0a 4f 62 6a  4d 67 72 53 71 6c 4c 6f   TG...ObjMgrSqlLo
000070  67 09 44 65 74 61 69 6c  09 34 09 32 30 30 35 2d   g.Detail.4.2005-
000080  30 36 2d 31 38 20 31 30  3a 32 37 3a 32 32 09 42   06-18 10:27:22.B
000090  69 6e 64 20 76 61 72 69  61 62 6c 65 20 32 3a 20   ind variable 2:
0000a0  50 54 47 0d 0d 0a 4f 62  6a 4d 67 72 53 71 6c 4c   PTG...ObjMgrSqlL
0000b0  6f 67 09 44 65 62 75 67  09 35 09 32 30 30 35 2d   og.Debug.5.2005-
0000c0  30 36 2d 31 38 20 31 30  3a 32 37 3a 32 32 09 55   06-18 10:27:22.U
0000d0  73 65 72 20 73 65 61 72  63 68 20 73 70 65 63 3a   ser search spec:
0000e0  20 50 54 47 0d 0d 0a 4f  62 6a 4d 67 72 53 71 6c    PTG...ObjMgrSql
0000f0  4c 6f 67 09 44 65 62 75  67 09 35 09 32 30 30 35   Log.Debug.5.2005
000100  2d 30 36 2d 31 38 20 31  30 3a 32 37 3a 32 32 09   -06-18 10:27:22.
000110  55 73 65 72 20 73 6f 72  74 20 73 70 65 63 3a 20   User sort spec:
000120  4c 6f 63 61 6c 65 20 43  6f 64 65 0d 0d 0a 4f 62   Locale Code...Ob
000130  6a 4d 67 72 53 71 6c 4c  6f 67 09 44 65 62 75 67   jMgrSqlLog.Debug
000140  09 35 09 32 30 30 35 2d  30 36 2d 31 38 20 31 30   .5.2005-06-18 10
000150  3a 32 37 3a 32 32 09 53  79 73 74 65 6d 20 73 6f   :27:22.System so
000160  72 74 20 73 70 65 63 3a  20 0d 0d 0a 61 31 35 62   rt spec: ...a15b
000170  36 30 30 0d 0d 0a           ^^^^^^^^               600...

Notice the double \r and \n at the 000160 line.  They probably don't
belong there.  Also notice that all your line endings have an extra
\r.

Your program modified by me:

#!perl --

use strict;
use warnings;
use IO::Handle;

my $Infile = shift || "TestObjMgr.log";
open IN, $Infile or die "Open $Infile: $!";
my $linenum = 0;
while (<IN>) {
        chomp;  # remove any newline ending
        ++$linenum;
        print "$linenum: $_\n";
}
close IN;

__END__

Program output:

1:    ORDER BY
2:       T1.LOCALE_CODE
3: ObjMgrSqlLog Detail  4       2005-06-18 10:27:22     Bind variable 1: PTG
4: ObjMgrSqlLog Detail  4       2005-06-18 10:27:22     Bind variable 2: PTG
5: ObjMgrSqlLog Debug   5       2005-06-18 10:27:22     User search spec: PTG
6: ObjMgrSqlLog Debug   5       2005-06-18 10:27:22     User sort spec: Locale C
ode
7: ObjMgrSqlLog Debug   5       2005-06-18 10:27:22     System sort spec:
8: a15b600

Line 8 is caused by the \r\r\n at the end of line 7 (see dump).

The double \r in your text file could be caused by writing like:
        print "some text\r\n";

That's a no-no unless you're in binary mode.  Just use \n without
the \r.  Windoze will add a \r in for you.

There's no easy way to fix the line 7-8 error, but you can fix the
double \r error by just changing the print above to
        print "$_\n";
and redirecting to a new file.  The new file should have \r\n on each
line rather than \r\r\n.

-- 
  ,-/-  __      _  _         $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