
Laurent_R
Enthusiast
Feb 2, 2013, 11:04 AM
Post #2 of 3
(161 views)
|
|
Re: [Raju_P] Program to filter and remove duplicates
[In reply to]
|
Can't Post
|
|
Did you start to write something? Assuming you know how to open and read a file line by line, you could use something like this to keep only the cities:
while (my $line = <$input_file>) { chomp $line; next unless $line =~ /City\s*$/; # discards lines which are not cities my @temp_array = split /\s*:/; # split the line into an array my $city = shift @temp-array; # get the city name # now try to find duplicates } For removing duplicates, the idiomatic way is to use a hash. You check if the city name exists in the hash; if it does exist, it is a duplicate; if not, add it to to the hash and print the line out.
(This post was edited by Laurent_R on Feb 3, 2013, 2:21 AM)
|