Advertisement
Guest User

perl

a guest
Jul 28th, 2012
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.15 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3.  use Text::CSV;
  4. # use strict;
  5. # use warnings;
  6. # use diagnostics;
  7.  use utf8;
  8.  
  9.  binmode(STDOUT, ":utf8");
  10.  
  11.  my @rows;
  12.  my $field;
  13.  my $outlook;
  14.  
  15.  # Outlook -> LDAP
  16.  my %mapping = ("Vorname" => "givenName",
  17.     "Nachname" => "sn",
  18.     "Firma" => "o",
  19.     "Straße geschäftlich" => "street",
  20.     "Ort geschäftlich" => "l",
  21.     "Postleitzahl geschäftlich" => "postalCode",
  22.     "Fax geschäftlich" => "facsimileTelephoneNumber",
  23.     "Telefon geschäftlich" => "telephoneNumber",
  24.     "Mobiltelefon" => "mobile",
  25.     "E-Mail-Adresse" => "mail",
  26.     "E-Mail 2: Adresse" => "mail",
  27.     "E-Mail 3: Adresse" => "mail");
  28.    
  29.  my $csv = Text::CSV->new ( { binary => 1, eol => $/ } )  # should set binary attribute.
  30.     or die "Cannot use CSV: ".Text::CSV->error_diag ();
  31.  
  32.  open my $fh, "<:encoding(utf8)", "foo.csv" or die "foo.csv: $!";
  33.  $csv->column_names($csv->getline($fh));
  34.  my $hr = $csv->getline_hr_all($fh);  # HashRef
  35.  
  36. for my $hashref (@$hr) {
  37.     foreach $outlook (keys %mapping) {
  38.         print "Outlook: ".$outlook."\t";
  39.         print "--> ".$mapping{$outlook}."--> ".$hashref->{$mapping}."\n";
  40.     }
  41. }
  42.  $csv->eof or $csv->error_diag();
  43.  close $fh;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement