songahji has asked for the wisdom of the Perl Monks concerning the following question:
I am wondering is there any module that collects a country list from a paragraph or stream of data?
Ex: I want Mexico but not New Mexico
I wonder there must be other super set thing like this
Hmm, I could have generate the list of country manually and start regex loop.
Cheers,sub get_country { my $data = shift; # let $data be one line of data, thus open IN, ">country.lis"; @country_list = <IN>; # <IN> is file handle reading the country li +st; close IN; for $c (@country_list) { if ($data =~ m/(\w+)\s+$c\s+/) { next if (($c eq 'Mexico') && (lc($1) eq 'new' ) ); push(@my_bucket, $c); } } return \@my_bucket; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Collecting Country in a paragraph
by ikegami (Patriarch) on Apr 25, 2006 at 21:08 UTC | |
by songahji (Friar) on Apr 26, 2006 at 14:40 UTC | |
|
Re: Collecting Country in a paragraph
by davidrw (Prior) on Apr 25, 2006 at 20:52 UTC | |
by songahji (Friar) on Apr 26, 2006 at 14:41 UTC | |
|
Re: Collecting Country in a paragraph
by Schuk (Pilgrim) on Apr 25, 2006 at 20:33 UTC |