"Fossies" - the Fresh Open Source Software Archive

Member "absence-v2.1/utils/import-countries.pl" (20 Oct 2013, 1939 Bytes) of package /linux/www/web-absence-2.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "import-countries.pl" see the Fossies "Dox" file reference documentation.

    1 #!/usr/bin/perl
    2 
    3 #======================================================================
    4 #    This file is part of Absence.
    5 #
    6 #    Absence is free software: you can redistribute it and/or modify
    7 #    it under the terms of the GNU General Public License as published by
    8 #    the Free Software Foundation, either version 3 of the License, or
    9 #    (at your option) any later version.
   10 #
   11 #    Absence is distributed in the hope that it will be useful,
   12 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
   13 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14 #    GNU General Public License for more details.
   15 #
   16 #    You should have received a copy of the GNU General Public License
   17 #    along with Absence.  If not, see <http://www.gnu.org/licenses/>.
   18 #======================================================================
   19 
   20 # copyright Robert Urban
   21 
   22 use AbsenceImport;
   23 
   24 my %VALUES = (
   25     database_user   => 'absence',
   26     database_pass   => 'absence',
   27     database_name   => 'absence',
   28     database_host   => undef,
   29 );
   30 
   31 importCountries('..');
   32 
   33 sub importCountries
   34 {
   35     my $srcdir = shift;
   36 
   37     AbsenceImport::init(
   38         $VALUES{database_user},
   39         $VALUES{database_pass}, 
   40         $VALUES{database_name}, 
   41         $VALUES{database_host}, 
   42     );
   43 
   44     verbose("loading country names and codes into database");
   45 
   46     my $input_file = "$srcdir/misc/iso3166-countrycodes.txt";
   47     my $fh = FileHandle->new($input_file);
   48     defined($fh)
   49         || die "failed to open iso-country-code file [$input_file]: $!";
   50     my $parsing = 0;
   51     my @list;
   52     while(<$fh>) {
   53         chomp;
   54         next if (/^\s*$/);
   55         if ($parsing) {
   56             if (/^(\S+(?:\s+\S+)*?)\s+(\S{2})\s+(\S{3})\s+(\d{3})\s*$/) {
   57                 my ($name, $two, $three, $num) = ($1, $2, $3, $4);
   58                 push(@list, { code => $two, name => $name });
   59                 verbose("code=[$two], name=[$name]");
   60             }
   61         }
   62         elsif (/^-{50,}$/) {
   63             $parsing = 1;
   64         }
   65     }
   66     $fh->close;
   67 
   68     AbsenceImport::loadCountryTable(\@list);
   69 }
   70 
   71 sub verbose
   72 {
   73     my $msg = shift;
   74 
   75     print "$msg\n";
   76 }