in reply to Perl Module for identifying country name
You can search for any group of strings you wish to. The problem is, what are the possible values. Will it be the English name or the German on: Germany or Deutchland? Will it be the current name or an older one: Myamar or Burma? Sri Lanka or Ceylon? Mumbai or Bombay?
If you have a file with one value per line, you can use "grep -f countries datafile" to examine datafile for all the countries in the countries file. The perl equivalent is simple:
- read in the set of countries into an array
- form into a regular expression which will capture the found string:
my $re_text = join '|', map {($_)} @countries; my $re = rx/$re_text/;
- and then test each input line against the re:
while ( my $line = <$fh>) { chomp $line; my $found = ($line =~ /$re/); # Profit! }
As Occam said: Entia non sunt multiplicanda praeter necessitatem.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Perl Module for identifying country name
by CountZero (Bishop) on Aug 03, 2012 at 17:20 UTC |
In Section
Seekers of Perl Wisdom