1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
#!/usr/bin/perl #use strict; use warnings; use Text::CSV; my %datei = ( shop => 'xt_customers.csv', wawi => 'xt_customers.txt', neu => 'all_customers.csv', ); sub load_cache { my $file = shift; my %cache; my $csv = Text::CSV->new ( { binary => 1 , sep_char => ";" } ) or die "File not found: ".Text::CSV->error_diag (); my $row; open my $fh, "<:encoding(iso-8859-1)", $file or die $file." $!"; while ( $row = $csv->getline ( $fh ) and ref $row eq 'ARRAY') { $cache{'ID'}{@$row[0]} = $cache{'Mail'}{@$row[6]} = $row; } return \%cache; } my $cache_shop = load_cache( $datei{'shop'} ); my $cache_wawi = load_cache( $datei{'wawi'} ); my $cache_neu = %{ load_cache( $datei{'shop'} ) }{'ID'}; for my $ID ( keys %{ $cache_wawi{'ID'} }) { $cache_neu{ $ID } = $cache_wawi{'ID'}{ $ID } if not exists $cache_shop{'ID'}{ $ID } and not exists $cache_shop{'Mail'}{ $cache_wawi{'ID'}{$ID}[6] }; } for my $row ( values %$cache_neu ) { print join(';', @$row[0..17])
1 2 3 4 5 6 7 8 9 10 11 12 13
while( my $row = $csv->getline ){ &cb($row) } # Die Callbackfunktion macht die Zuordnung index => name sub cb{ my $r = shift; my $id = $r->[0]; # Beispiel ID auf index [0] $DATA->{$id}{name} = $r->[1]; $DATA->{$id}{vname} = $r->[2]; $DATA->{$id}{plz} = $r->[3]; # usw. }
$cache{'ID'}{ $row->[0] } = $cache{'Mail'}{ $row->[6] } = $row;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#!/usr/bin/perl #use strict; use warnings; use Text::CSV; my %datei = ( shop => 'xt_customers.csv', wawi => 'xt_customers.txt', neu => 'all_customers.csv', ); sub load_cache { my $file = shift; my %cache; my $csv = Text::CSV->new ( { binary => 1 , sep_char => ";" } ) or die "File not found: ".Text::CSV->error_diag (); my $row; open my $fh, "<:encoding(iso-8859-1)", $file or die $file." $!"; while ( $row = $csv->getline ( $fh ) and ref $row eq 'ARRAY') { $cache{'ID'}{ $row->[0] } = $cache{'Mail'}{ $row->[6] } = $row; #$cache{'ID'}{@$row[0]} = $cache{'Mail'}{@$row[6]} = $row; } return \%cache; } # lade beide dateien my $cache_shop = load_cache( $datei{'shop'} ); my $cache_wawi = load_cache( $datei{'wawi'} ); my $cache_neu = (load_cache $datei{shop} )->{ID}; # kopiere alle zeilen aus wawi in neuen shop deren id oder mail nicht im shop ist for my $ID ( keys %{ $cache_wawi{'ID'} }) { $cache_neu{ $ID } = $cache_wawi{'ID'}{ $ID } if not exists $cache_shop{'ID'}{ $ID } and not exists $cache_shop{'Mail'}{ $cache_wawi{'ID'}{$ID}[6] }; } # gib die neue shopliste aus for my $row ( values %$cache_neu ) { print join(';', @$row[0..17]);print"\n" }
your code or data here
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; $Data::Dumper::Useqq = 1; #!/usr/bin/perl #use strict; use warnings; use Text::CSV; my %datei = ( shop => 'xt_customers.csv', wawi => 'xt_customers.txt', neu => 'all_customers.csv', ); sub load_cache { my $file = shift; my %cache; my $csv = Text::CSV->new ( { binary => 1 , sep_char => ";" } ) or die "File not found: ".Text::CSV->error_diag (); my $row; open my $fh, "<:encoding(iso-8859-1)", $file or die $file." $!"; while ( $row = $csv->getline ( $fh ) and ref $row eq 'ARRAY') { $cache{'ID'}{ $row->[0] } = $cache{'Mail'}{ $row->[6] } = $row; #$cache{'ID'}{@$row[0]} = $cache{'Mail'}{@$row[6]} = $row; } return \%cache; } # lade beide dateien my $cache_shop = load_cache( $datei{'shop'} ); my $cache_wawi = load_cache( $datei{'wawi'} ); my $cache_neu = (load_cache $datei{shop} )->{ID}; # kopiere alle zeilen aus wawi in neuen shop deren id oder mail nicht im shop ist for my $ID ( keys %{ $cache_wawi->{'ID'} }) { $cache_neu->{ $ID } = $cache_wawi->{'ID'}->{ $ID } if not exists $cache_shop->{'ID'}->{ $ID } and not exists $cache_shop->{'Mail'}->{ $cache_wawi->{'ID'}->{$ID}->[6] }; } # gib die neue shopliste aus for my $row ( values %$cache_neu ) { print join(';', @$row[0..17]);print"\n" }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
$Data::Dumper::Useqq = 1;
#!/usr/bin/perl
#use strict;
use warnings;
use Text::CSV;
my %datei = (
shop => 'xt_customers.csv',
wawi => 'xt_customers.txt',
neu => 'all_customers.csv',
);
sub load_cache {
my $file = shift;
my %cache;
my $csv = Text::CSV->new ( { binary => 1 , sep_char => ";" } )
or die "File not found: ".Text::CSV->error_diag ();
my $row;
open my $fh, "<:encoding(iso-8859-1)", $file or die $file." $!";
while ( $row = $csv->getline ( $fh ) and ref $row eq 'ARRAY') {
$cache{'ID'}{ $row->[0] } = $cache{'Mail'}{ $row->[6] } = $row;
#$cache{'ID'}{@$row[0]} = $cache{'Mail'}{@$row[6]} = $row;
}
return \%cache;
}
# lade beide dateien
my $cache_shop = load_cache( $datei{'shop'} );
my $cache_wawi = load_cache( $datei{'wawi'} );
my $cache_neu = (load_cache $datei{shop} )->{ID};
# kopiere alle zeilen aus wawi in neuen shop deren id oder mail nicht im shop ist
for my $ID ( keys %{ $cache_wawi->{'ID'} }) {
$cache_neu->{ $ID } = $cache_wawi->{'ID'}->{ $ID }
if not exists $cache_shop->{'ID'}->{ $ID }
and not exists $cache_shop->{'Mail'}->{ $cache_wawi->{'ID'}->{$ID}->[6] };
# and not exists $cache_shop->{'Mail'}->{ $cache_wawi->{'ID'}->{$ID}->[6] };
}
# gib die neue shopliste aus
for my $row ( values %$cache_neu ) { print join(';', @$row[0..17]);print"\n" }
1
2
3
4
5
6
7
if ($cache_shop->{'Mail'}->{ $ID } = $cache_wawi->{'Mail'}->{ $ID })
{
print "treffer, beide gleich";
}
else
{
}
if ($cache_shop->{'Mail'}->{ $ID } = $cache_wawi->{'Mail'}->{ $ID })