Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I'd be grateful for any pointers into improving this sub. Thanks.use strict; use warnings; my $text = "letter.txt"; #open the file open my $fh, '<', $text or die "Can't read $text, $!"; my $letter = do { local $/; <$fh> }; close $fh; $letter =~ s/\s+\*//g; my @sidenotes = split /(?=\[Sidenote:)/, $letter; foreach my $text (@sidenotes) { my $name = find_name($text); print " $name\n"; } #sub to find possible names in the text sub find_name { my $name; my $n_text = shift or die "no text passed"; my @word = split ' ', $n_text; @word =~ m/\w{2}/i; foreach my $word (@word) { if ($word =~ m/^[A-Z]/) { if ($word[0] ne "[Sidenote:") { $name = $word[0]." ".$word[1]; } } } return $name; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Finding a capitalised pair of words in a text
by jwkrahn (Abbot) on Jan 02, 2010 at 02:37 UTC | |
|
Re: Finding a capitalised pair of words in a text
by AnomalousMonk (Archbishop) on Jan 02, 2010 at 14:13 UTC |