Re: [perl] zuordnungsproblem [auf Viren überprüft]

Jan Trippler <[email protected]>
Newsgroups gmane.linux.suse.programming
Message-ID <[email protected]>
Moin,

Am Mittwoch, 15. Februar 2006 17:26 schrieb Hans Moser:
> Hallo!
>
> Ich habe einen Datensatz aus mit Komma getrennten Werten:
> feld1;wert1;feld2;wert2;feld3;wert3;
>
> Daraus einen Hash zu bilden, wäre ja nicht das Problem.
> Letztendlich soll daraus ein LDIF-Datensatz werden. Dazu muß ich
> die Feldnamen anhand einer weiteren Zuordnung in die
> entsprechenden Attribute ändern.
> feld1 -> attribute1
> feld2 -> attribute2
>
> Wie verknüpfe ich am besten die Ausgangs"tabelle" mit meiner
> LDIF-Übersetzungs"tabelle", damit ich folgende Zuordnung erhalte:
> feld1 - wert1 ---> attribute1 - wert1   ?
> Ein Hash mit einem 2 dimensionalen Array?

Meinst Du sowas?

<schnipp>
#! /usr/bin/perl

use strict;
use warnings;

my %ldif = ("feld1" => "attribute1",
            "feld2" => "attribute2",
            "feld3" => "attribute3");

my $line = "feld1;wert1;feld2;wert2;feld3;wert3;";
my %out = ();

my @f = split /;/, $line;
for (my $i = 0; $i < $#f; $i+=2) {
  my @a = ($ldif{$f[$i]}, $f[$i+1]);
  $out{$f[$i]} = \@a;
}

foreach (sort keys %out) {
  my $aref = $out{$_};
  print $_, " = ", @$aref[1], " ---> ", @$aref[0], " = " ,
        @$aref[1], "\n";
}

exit 0;
<schnapp>

cu
Jan

-- 
Um die Liste abzubestellen, schicken Sie eine Mail an:
    [email protected]
Um eine Liste aller verfügbaren Kommandos zu bekommen, schicken
Sie eine Mail an: [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.