c0d34w4y has asked for the wisdom of the Perl Monks concerning the following question:
Fella Monks... The code below is a demo of my attempt at writing a little function to retreave N first sentences from a string. I wonder if there would be any suggestion on your part as to other implementations to achieve similar results? Cheers, c0d34w4ymy $s = "foo. bar. foobar. foo bar."; my $p = get_nsentences($s,2); # $p = "foo. bar."; print $p; print "done\n"; ## SUBS # get n first sentences from a given string. sub get_nsentences { my $source_txt = $_[0]; my $ret_txt = ""; # i know this looks twisted... for($i=$_[1]||1;$i>0 && length($source_txt);$i--) { $source_txt =~ + s/([^\.]+\.)/(($ret_txt.=$1)&&"")/e; } return $ret_txt; }
print join(" ", map { sprintf "%#02x", $_ }unpack("C*",pack("L",0x1234 +5678)))
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Retreaving N first sentences from text.
by Beatnik (Parson) on Dec 15, 2001 at 03:48 UTC | |
|
Re: Retreaving N first sentences from text.
by Zaxo (Archbishop) on Dec 15, 2001 at 04:05 UTC | |
by c0d34w4y (Acolyte) on Dec 15, 2001 at 04:20 UTC | |
|
Re: Retreaving N first sentences from text.
by dws (Chancellor) on Dec 15, 2001 at 03:58 UTC | |
|
Re: Retreaving N first sentences from text.
by dragonchild (Archbishop) on Dec 15, 2001 at 03:49 UTC | |
by boo_radley (Parson) on Dec 15, 2001 at 03:55 UTC | |
by blakem (Monsignor) on Dec 15, 2001 at 03:59 UTC |