1#! /usr/bin/perl -w 2 3use strict; 4 5use Geo::Postcodes::NO 0.30; 6 7################################################################################ 8# # 9# selection_no # 10# ------------ # 11# Arne Sommer - perl@bbop.org - 9. September 2006 # 12# # 13################################################################################ 14 15unless (@ARGV == 2) 16{ 17 print "Usage: selection_no <field> <string>\n"; 18 print "Legal fields: ", join(" ", Geo::Postcodes::NO::get_fields()), ".\n"; 19 exit; 20} 21 22my $field = shift(@ARGV); 23my $string = shift(@ARGV); 24 25my @fields; 26 27if (Geo::Postcodes::NO::is_field($field)) # Legal field 28{ 29 @fields = Geo::Postcodes::NO::get_fields(); 30 # Get all the fields supported by this module. 31 32 foreach my $m (@fields) 33 { 34 printf("%-14s", ucfirst($m)); # Print headers for each column 35 } 36 print "\n"; 37 38 Geo::Postcodes::NO->selection_loop(\&print_it, $field, $string); 39 # Call each postcode object on to the 'loop' procedure. 40 41 print "\n"; 42} 43else # illegal field. 44{ 45 print "Not a legal field '$field'.\n"; 46} 47 48sub print_it 49{ 50 my $object = shift; 51 foreach my $m (@fields) # Iterate over the fields for each object 52 { 53 printf("%-14s", $object->$m() || ""); # Print the column data, or nothing if empty 54 } 55 print "\n"; 56} 57