Lingua::EN::Splitter to the rescue:
#!/usr/bin/perl
use strict;
use warnings;
use Lingua::EN::Splitter;
my @strings = (
q|one two 'three'|,
q|yes I am 'me'|,
);
my %config = (
minlen => 3,
maxlen => 32,
locale => "en_US.ISO_8859-1",
);
my $split = Lingua::EN::Splitter->new;
my %count;
for my $str (@strings){
print "$str\n";
my $words = $split->words($str);
$count{$_}++ for @$words;
for my $word (sort @$words) {
$_ = length $word;
next if $_ < $config{minlen} or $_ > $config{maxlen};
print $word, ' -> ', $count{$word}, "\n"
}
print '-' x 10, "\n";
}
__END__
Output:
one two 'three'
one -> 1
three -> 1
two -> 1
----------
yes I am 'me'
yes -> 1
--
perl -MO=Deparse -e"u j t S n a t o e h r , e p l r a h k c r e"
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|