Hi, all

i am stuck with a problem and i cannot find any solution to it. I have to
mention beforehand that i still am a beginner in Perl, so give me some
allowance for my code...

OK - i have this ascii-file with the codes and the names of German bancs
(some 5000+), which looks like this:
...
10030600BANKHAUS OSWALD KRUBER
13444BERLIN                        091
10030700GRIES & HEISSEL  BANKIERS
14193BERLIN                        111
10040000COMMERZBANK BERLIN (WEST)
10891BERLIN                        131
10050000LANDESBANK BERLIN GZ ZGL BERLINER SPARKASSE
10889BERLIN                        201
10050001LANDESBANK BERLIN GIROZENTRALE
10889BERLIN                        201
10050005LANDESBANK BERLIN GIROZENTRALE E 1
10889BERLIN                        091
10050006LANDESBANK BERLIN GIROZENTRALE E 2
10889BERLIN                        091
10050500LBS OSTDEUTSCHE LANDESBAUSPARKASSE
10117BERLIN                        091
10050600WESTDEUTSCHE LANDESBANK GIROZENTRALE
10117BERLIN                        081
10050999DEUTSCHE GIROZENTRALE DEUTSCHE KOMMUNALBANK
10249BERLIN                        091
10060198PAXBANK
14005BERLIN                        061
...

To import it into a database and for normalization reasons i have to build 3
tables and accordingly create 3 files:

> banc-code (unique), banc-name, zip-code-ID ->blz2.txt
> zip-code-ID, zip-code, city-ID
> city-ID, city

with the enclosed Perl - listing i am only building to files: _blz2.txt_
and  _orte2.txt_. The latter contains: zip-code-ID, zip-code, city

_blz2.txt_ looks like this:

...
1003060;BANKHAUS OSWALD KRUBER;20
1003070;GRIES & HEISSEL  BANKIERS;21
1004000;COMMERZBANK BERLIN (WEST);22
1005000;LANDESBANK BERLIN GZ ZGL BERLINER SPARKASSE;23
1005000;LANDESBANK BERLIN GIROZENTRALE;24   #(wrong should be 23)
1005000;LANDESBANK BERLIN GIROZENTRALE E 1;25  #(wrong should be 23)
1005000;LANDESBANK BERLIN GIROZENTRALE E 2;26  #(wrong should be 23)
1005050;LBS OSTDEUTSCHE LANDESBAUSPARKASSE;27      # these two are also
wrong
1005060;WESTDEUTSCHE LANDESBANK GIROZENTRALE;28   # it should be 24; the
following nr.
1005099;DEUTSCHE GIROZENTRALE DEUTSCHE KOMMUNALBANK;29    #are tobe changed
as well
1006019;PAXBANK;30
....
_orte2.txt_ looks like:

...
20;13444 BERLIN
21;14193 BERLIN
22;10891 BERLIN
23;10889 BERLIN
24;10889 BERLIN
25;10889 BERLIN
26;10889 BERLIN
27;10117 BERLIN
28;10117 BERLIN
29;10249 BERLIN
30;14005 BERLIN
...
which is not ok, because i am trying to exclude the repeating numbers (23 -
26 and 27 -28).
It should look like this:

...
20;13444 BERLIN
21;14193 BERLIN
22;10891 BERLIN
23;10889 BERLIN
24;10117 BERLIN
25;10249 BERLIN
26;14005 BERLIN
...

now i am stuck right here. I just do not get my loops right. The file
'orte.txt' is used to check the zip-codes and contains the same as
'orte2.txt' right now.  'blz.asc' ist the original file that i start out
with (the first listing above with lots of whitespace in between and in the
ends of the lines).

This is the Perl programm:
(all the 'print to STOUT' are just for debugging)

#!perl -w
use Carp;

$datei ='c:/Perl/scripts/blz.asc';
$orte2 = 'c:/Perl/scripts/orte2.txt';
$orte = 'c:/Perl/scripts/orte.txt';
$blzen = 'c:/Perl/scripts/blz2.txt';
$i = 1;

open (DATEI, $datei) or die "Kann $datei nicht oeffnen: $!\n";
open (ORTE2, ">$orte2") or die "Kann $orte2 nicht oeffnen: $!\n";
open (ORTE, "$orte") or die "Kann $orte nicht oeffnen: $!\n";
open (BLZ, ">$blzen") or die "Kann $blzen nicht oeffnen: $!\n";

@datei =<DATEI>;
foreach $linie(@datei){
  substr($linie,-28)="";
  $linie =~ s/\s+$//;
  $blz = substr ($linie,0,7);
  $bank = substr ($linie,8);
  ($bank,$ort) = split (/\s{3,}/,$bank,2);
  $bank =~s/\s/ /;
  $plz = substr ($ort,0,5);
  $ortsname = substr ($ort,5);
  @orte = <ORTE>;

        # here i try to compare the zip-code, the mistake must be around
here

  for ($j = 1;$j<=$i;$j++){
    foreach $zeile(@orte){
  chomp $zeile;
  ($z,$plz_ort) = split(/;/,$zeile);
  $polz = substr ($plz_ort,0,5);
       print "POLZ:".$polz.";PLZ:".$plz.".\n";
       print "die ganze Zeile: ".$zeile."\nDie ID: ".$z."\nUnd die PLZ:
".$polz.".\n\n";
  if ($polz eq $plz){
       print "Ort schon vorhanden\n";
        next;
      }
    }
  }
  if ($polz eq $plz){
    print BLZ $blz.";".$bank.";".$i."\n";
    $i++;  print "i wurde oben um eins erhoeht: ".$i."\n";
  } else {
    print BLZ $blz.";".$bank.";".$i."\n";
    print ORTE2 $i.";".$plz." ".$ortsname."\n";
    $i++;  print "i wurde unten um eins erhoeht: ".$i.".\n";
  }
}
close (DATEI);
close (ORTE);
close (ORTE2);
close (BLZ);


I would appreciate any suggestion and help.
Thanks in advance.

Rudi Neumaier




_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users

Reply via email to