#! /usr/bin/perl -w
use strict;
use Geo::Postcodes::DK 0.30;
################################################################################
# #
# selection_dk #
# ------------ #
# Arne Sommer - perl@bbop.org - 9. September 2006 #
# #
################################################################################
unless (@ARGV == 2)
{
print "Usage: selection_dk <field> <string>\n";
print "Legal fields: ", join(" ", Geo::Postcodes::DK::get_fields()), ".\n";
exit;
}
my $field = shift(@ARGV);
my $string = shift(@ARGV);
my @fields;
if (Geo::Postcodes::DK::is_field($field)) # Legal field
{
@fields = Geo::Postcodes::DK::get_fields();
# Get all the fields supported by this module.
foreach my $m (@fields)
{
printf("%-14s", ucfirst($m)); # Print headers for each column
}
print "\n";
Geo::Postcodes::DK->selection_loop(\&print_it, $field, $string);
# Call each postcode object on to the 'loop' procedure.
print "\n";
}
else # illegal field.
{
print "Not a legal field '$field'.\n";
}
sub print_it
{
my $object = shift;
foreach my $m (@fields) # Iterate over the fields for each object
{
printf("%-14s", $object->$m() || ""); # Print the column data, or nothing if empty
}
print "\n";
}