Thread Variable in Sub-Routine unbekannt (20 answers)
Opened by tecker at 2008-05-07 16:19

tecker
 2008-05-07 16:53
#109392 #109392
User since
2008-02-26
77 Artikel
BenutzerIn
[Homepage] [default_avatar]
Ok, hier mal die detailiertere Version und Fehlermeldung. In dem Regex hole ich mir neben der ID noch das Datum raus, da ich das spätere noch verwende.

Bin auch dankbar für Vorschläge was genrelle Syntax angeht oder falls was uneffizient oder unsauber ist ;)

Vielen Dank schonmal



Code: (dl )
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);


Beim ausführen erscheint für jedes gefundene File:

Use of uninitialized value in concatenation (.) or string at db.pl line 47.
ID: 030858 - File:
Use of uninitialized value in concatenation (.) or string at db.pl line 49.
cat: csv_all/: Ist ein Verzeichnis
Use of uninitialized value in concatenation (.) or string at db.pl line 47.
ID: 030859 - File:
Use of uninitialized value in concatenation (.) or string at db.pl line 49.




View full thread Variable in Sub-Routine unbekannt