View Single Post
  #3   (View Single Post)  
Old 12th December 2011
ocicat ocicat is offline
Administrator
 
Join Date: Apr 2008
Posts: 3,319
Default

Quote:
Originally Posted by J65nko View Post
...a Perl script to count the number of comma's...
Consider the following (assuming comma are not found in the data...):
Code:
#!/bin/env perl

use strict;
use warnings;

# array of test strings
my @a = (',', ',,', ',,,');

my $max = 0;
foreach my $line (@a) {
    my @matches = ($line =~ /(\,)/g);
    $max = @matches if @matches > $max;
}

print "max #occurrences = $max\n";
TIMTOWTDI.


Last edited by ocicat; 12th December 2011 at 07:01 AM.
Reply With Quote