![]() |
|< 1 2 3 >| | ![]() |
21 Einträge, 3 Seiten |
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
#!/usr/bin/perl
use strict;
use DirHandle;
my $file;
my $filename;
my $id = 0;
my $dir = "csv_files";
my $dh = DirHandle->new($dir);
my @filelist = sort $dh->read();
{
foreach $file (@filelist)
if ($file =~ /datei_(\d+).csv/)
{
$filename = $file;
$filename =~ s/datei_(\d+).csv/$1/;
$id = $1;
# hier kommen noch diverse sql sachen
&update($file);
}
}
sup update{
my ($name) = @_;
print "ID: $id - Filename: $name\n";
my $filename = ...
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/perl
use strict;
use warnings;
use DirHandle;
use DBI;
##### Variablen ##############################
my $csv_dir = "csv_all";
my $filename;
my $file;
my $id = 0;
my ($a,$b,$c);
my $dbh = DBI ->connect('DBI:mysql:table', 'user', 'pw', {PrintError => 1});
my $dh = DirHandle->new($csv_dir);
my @filelist = sort $dh->read();
{
foreach $file (@filelist)
{
if($file =~ /extasc_cdr_(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})_(\d+).csv/)
{
$filename = $file;
$filename =~ s/extasc_cdr_(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})_(\d+).csv/$1 $2 $3 $4 $5 $6 $7/;
$id = $7;
# select auf ID in Datenbank machen um zu pruefen ob die csv-Datei schon in DB eingelesen wurde
my $sql_id_select = "SELECT * FROM csv_id WHERE csv_id=$id";
my $execute_select = $dbh->do($sql_id_select) or warn $dbh->errstr;
if ($execute_select eq "0E0") {&update_db($file);}
else {print "-\n";}
}
}
}
sub update_db{
# CSV-ID in Datenbank speichern
my $sql_id_insert = "INSERT into csv_id VALUES('',$id)";
my $execute_insert = $dbh->do($sql_id_insert) or warn $dbh->errstr;
print "ID: $id - File: $file\n";
open(DATEI, "cat $csv_dir/$file |") or die "Fehler beim oeffnen von $file: $!\n";
while(<DATEI>)
{
chomp $_;
(my @spalten) = split (/\,/, $_);
$a = $spalten[0];
$b = $spalten[1];
$c = $spalten[2];
}
}
$dbh->disconnect;
close(DATEI);
![]() |
|< 1 2 3 >| | ![]() |
21 Einträge, 3 Seiten |