troubleshooting Question

Counting rows in a list 7

Avatar of Europa MacDonald
Europa MacDonaldFlag for United Kingdom of Great Britain and Northern Ireland asked on
Programming Languages-OtherProgrammingPerl
5 Comments1 Solution459 ViewsLast Modified:
I have a list, with data on each row separated by a comma. I have several columns of data.



It is the data in the 10th column that I have to count. With the result for the above sample list being

60000 3
03030 2
02220 1

The thing is, it is not a number, I have to look at it as text, and count the variations as I find them.

I tried using this code

use strict;
use warnings;
open M,"<master_sorted_002_reduced.vim" or die "master_sorted_002_reduced.vim $!";
my $c=0;

$c+= /[^,]*,[^,]*,[^,]*,[^,]*,[^,]*,[^,]*,[^,]*,[^,]*,[^,]*,(\d+)/ while <M>;

close M;
open C,">count4.txt" or die "count4.txt $!";
print C "$_ $c\n";
close C;

But it only seems to count the number of lines ?

Could you please help me with code which will count the rows, and report the variable and the number of each variable that it finds ? without treating it like a number ?

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros