This: ---------------- cut here ---------------- while(<DATA>) { $cnt=()=$_=~ /;/g; $matches{$cnt}++; } print "found $_ ; in $matches{$_} line(s)\n" foreach (sort {$b <=> $a } keys %matches); __DATA__ NEW ANALOGUE; A.PS.19.601; 0; 4;NA; 0;OFF;%;NO; 100.00000;0.00000;"ANALOGUE CARD #100 INPUT NO 01";FLOAT;FINISH; NEW ANALOGUE; A.PS.19.602; 1; 4;NA; 0;OFF;%;NO; 100.00000;0.00000;"ANALOGUE CARD #100 INPUT NO 02";FLOAT;FINISH; NEW ANALOGUE; A.PS.19.603; 2; 4;NA; 0;OFF;%;NO; 100.00000;0.00000;"ANALOGUE CARD #100 INPUT NO 03";FLOAT;FINISH; Just one ; And here are 2 semicolons: ;; ---------------- cut here ----------------
Will produce this output: $ perl matches.pl found 14 ; in 3 line(s) found 2 ; in 1 line(s) found 1 ; in 1 line(s) The "$cnt=()=$_=~/;/g/" is a TomC trick. Hope this helps Tobias > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On > Behalf Of EwenMarshall > Sent: Tuesday, December 05, 2006 12:23 PM > To: Perl-Win32-Users@listserv.ActiveState.com > Subject: RE: Counting Matches In A Line > > All I want to do is count the number of ;'s on each line of > 15,000'ish lined text file. The first 3 lines look like > (FINISH; is the end of 1 line): > > NEW ANALOGUE; A.PS.19.601; 0; 4;NA; 0;OFF;%;NO; 100.00000; > 0.00000;"ANALOGUE CARD #100 INPUT NO 01";FLOAT;FINISH; > NEW ANALOGUE; A.PS.19.602; 1; 4;NA; 0;OFF;%;NO; 100.00000; > 0.00000;"ANALOGUE CARD #100 INPUT NO 02";FLOAT;FINISH; > NEW ANALOGUE; A.PS.19.603; 2; 4;NA; 0;OFF;%;NO; 100.00000; > 0.00000;"ANALOGUE CARD #100 INPUT NO 03";FLOAT;FINISH; > > Basically the file is an export from a very old database and > there is not always the same amount of ;'s in each line. I've > been given the lovely task of changing the format so that > each line in the file can be imported into an access database > from a ; delimited file in the correct order. The match > condition is number of ; in 1 line > Output: > found 14 ; in 1,232 lines > found 13 ; in 7,456 lines > found 12 ; in 2,321 lines > > I only need total number of lines found. I do not know what > the max or min amount of ;'s there can be in one line. > > Ewen _______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs