On 2011.10.15.00.08, Chris Stinemetz wrote: > I am trying to create a Perl script that will scan a file using regex > to match certain patterns and return uniq names and the total count of > each match. > > With the sample input data (on the far bottom) the return value should > be CELL 20 in Column 1 with 2 Counts of CDM HEH in the third column.
Now I'm starting to think you weren't asking for help on the matching, but rather on the summarizing. What would really help is if you could also give an example of the output you want. For that you probably want a hash (or hash-of-hashes or ... some data structure with a hash) -- I think of a hash anytime I see words like "unique". I'll just pretend that you will have a unique cell, and then a count of the CDM type for each. This might not actually make sense for your data though. So we can build such a hash by hand: my $summary = {}; # Line: 00 REPT:CELL 20 CDM 1, CRC, HEH $summary->{"20"}->{"CDM"}->{"HEH"}++; # Cell 20, CDM HEH # Line: 00 REPT:CELL 20 CDM 1, CRC, HEH $summary->{"20"}->{"CDM"}->{"HEH"}++; # Cell 20, CDM HEH But really I am probably speaking gibberish until you provide some sample output. Especially it would be good to have other test cases -- like what other cells would look like, or if there could be non-HEH CDMs. --Brock -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/