From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of ruth wambua Sent: 28 November 2006 15:12 To: [email protected] Subject: RE: Phone Count
> Hi, > > I'm just a beginner. > Please help me with a source code I would use to count Phones ( each single letter of a word). For instance, in > a corpus of 10,000 words I'm able to count the number of a's, e's, th's... I'm guessing that you don't really mean single letters. There are probably a number of approaches, any number of which may already have been implemented (see http://search.cpan.org). The example below demonstrates one approcah that mey do what you want, but in the absence of a better description of what you want to do, it is only a guess. ------------------------------------------------- use strict; use warnings; my @letters = ( # Single letters ('a' .. 'z'), # Combinations qw{th sh ch} ); # Regexp to match letters and combinations. Note they are sorted by # length to make sure that combinations match before single letters. my $phoneRE = qr{(@{[join("|", sort {length($b) <=> length($a)} @letters)]})}; # Counts initialised to zero. my %count = map {$_, 0} @letters; # Count matches while (my $line = <DATA>) { ++$count{$_} foreach lc($line) =~ /$phoneRE/g } # Print results print "$_\t$count{$_}\n" for @letters; __DATA__ This is some test data. Check that this works too, as it should. ------------------------------------------------- HTH -- Brian Raven _________________________________________ The information contained in this e-mail is confidential and solely for the intended addressee(s). Unauthorised reproduction, disclosure, modification, and/or distribution of this email may be unlawful. If you have received this email in error, please notify the sender immediately and delete it from your system. The views expressed in this message do not necessarily reflect those of Atos Euronext Market Solutions. _________________________________________ ================================= Atos Euronext Market Solutions Disclaimer ================================= The information contained in this e-mail is confidential and solely for the intended addressee(s). Unauthorised reproduction, disclosure, modification, and/or distribution of this email may be unlawful. If you have received this email in error, please notify the sender immediately and delete it from your system. The views expressed in this message do not necessarily reflect those of Atos Euronext Market Solutions. L'information contenue dans cet e-mail est confidentielle et uniquement destinee a la (aux) personnes a laquelle (auxquelle(s)) elle est adressee. Toute copie, publication ou diffusion de cet email est interdite. Si cet e-mail vous parvient par erreur, nous vous prions de bien vouloir prevenir l'expediteur immediatement et d'effacer le e-mail et annexes jointes de votre systeme. Le contenu de ce message electronique ne represente pas necessairement la position ou le point de vue d'Atos Euronext Market Solutions. _______________________________________________ ActivePerl mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
