#!/usr/bin/perl -l # # $Id: extract 2592 2003-12-21 00:33:01Z jmates $ # # The author disclaims all copyrights and releases this document into # the public domain. use Benchmark; @a = qw(a,b,c a,c,d e,c,d a,m,q d,e,g,r a,z,e,q b,b,b d,d,r,h); # test routines actually work here #&split; #print $c{$_}, "\t", $_ for keys %c; #®explus; #print $c{$_}, "\t", $_ for keys %c; timethese(500000, { 'split' => \&split, 'regex' => \®ex, 'regexplus' => \®explus, }); sub split { %c = (); $c{(split ',', $_, 2)[0]}++ for @a; } sub regex { %c = (); for (@a) { $c{$1}++ if m/(^.+?),.*/g; } } sub regexplus { %c = (); for (@a) { $c{$1}++ if m/^([^,]+)/g; } }