"Fossies" - the Fresh Open Source Software Archive

Member "absence-v2.1/utils/load-country-table.pl" (20 Oct 2013, 1770 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 "load-country-table.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 FileHandle;
   23 use Getopt::Long;
   24 
   25 use AbsenceImport;
   26 
   27 my ($in_file, $db_user, $db_pass, $db_host, $db_name);
   28 
   29 my $res = GetOptions(
   30     'file|f=s'  => \$in_file,
   31     'user|u=s'  => \$db_user,
   32     'pass|p=s'  => \$db_pass,
   33     'host|h=s'  => \$db_host,
   34     'name|n=s'  => \$db_name,
   35 );
   36 
   37 defined($in_file) || die "usage: $0 -file <input-file>\n";
   38 (!defined($db_user) || !defined($db_pass) || !defined($db_host) ||
   39     !defined($db_name)) && die "DB user/pass/host/name missing\n";
   40 
   41 
   42 my $fh = FileHandle->new($in_file);
   43 defined($fh) || die "unable to open file [$in_file] for reading: $!";
   44 
   45 <$fh>;  # throw away column-labels
   46 
   47 my @arr;
   48 while(<$fh>) {
   49     chomp;
   50     my ($name, $code) = split(/;/, $_);
   51     #printf("%2s %s\n", $code, $name);
   52     push(@arr, { iso => lc($code), name => $name });
   53 }
   54 
   55 $fh->close;
   56 
   57 AbsenceImport::init($db_user, $db_pass, $db_name, $db_host);
   58 
   59 AbsenceImport::loadCountryTable(\@arr);
   60 
   61 print "finished.\n";