in reply to Can not print hash element
Skipping duplicate cities and regexp
#!/usr/bin/perl -w use strict; use Data::Dumper; my $country; # Hash ref ;) my $sep = q{,}; while (<DATA>) { chomp; next if /\A\z/; /\s* (.+) \s* $sep \s* (.+) \s*/msx; next unless defined $1 and defined $2; grep { /$1/i } @{ $country->{$2} } or push @{ $country->{$2} }, $1; } print Dumper $country; __DATA__ Chicago, USA Frankfurt, Germany Berlin, Germany Washington, USA Helsinki, Finland Berlin, Germany New York, USA Freetown, Sierra Leone
hth,
PooLpi
|
|---|