EwenMarshall wrote, on Tuesday, December 05, 2006 2:23 PM : 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; : : Output: : found 14 ; in 1,232 lines : found 13 ; in 7,456 lines : found 12 ; in 2,321 lines
I think this is what you want (only slightly tested): my @semis; while (<IN>) { ++$semis[tr/;/;/]; } The tr/// operator counts all the occurrences of the translated character(s) in $_ (the default), and then you just increment the @semis array at the index of the number of semicolons found to indicate another line with that number of semicolons. Good luck, Joe Joseph Discenza, Senior Programmer/Analyst mailto:[EMAIL PROTECTED] Carleton Inc. http://www.carletoninc.com 574.243.6040 ext. 300 Fax: 574.243.6060 : -----Original Message----- : From: [EMAIL PROTECTED] : [mailto:[EMAIL PROTECTED] On : To: Perl-Win32-Users@listserv.ActiveState.com : Subject: RE: Counting Matches In A Line : : : 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 : : -----Original Message----- : From: [EMAIL PROTECTED] : [mailto:[EMAIL PROTECTED] On : Behalf Of Chris Wagner : Sent: 05 December 2006 18:50 : To: Perl-Win32-Users@listserv.ActiveState.com : Subject: Re: Counting Matches In A Line : : We need some more information. What is the match condition : and how do u find the number of matches? : : If ur just trying to record the number of "something" per : line so that u can go back and correlate the number to the : line, then u can't use foreach. U have to iterate over the : array so u can get the offset. : : for $i (0 .. $#data) { : $number = 0 + do_something; : $matchcount[$i] = $number; : } : : Now $matchcount[$i] corresponds to the number of matches in $data[$i]. : : : : : : : -- : REMEMBER THE WORLD TRADE CENTER ---=< WTC 911 >=-- : "...ne cede malis" : : 00000100 : : _______________________________________________ : Perl-Win32-Users mailing list : Perl-Win32-Users@listserv.ActiveState.com : To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs : : _______________________________________________ : Perl-Win32-Users mailing list : Perl-Win32-Users@listserv.ActiveState.com : To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs : _______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs