>I;m trying to parse one text file and insert it into database .
>Here is the example of Data
>CONTACT : Chemico Ltd.
>MANAGER : Michael Kor
>STATE: Blagoevgrad
>CODE : 4005
>City: Blagoevgrad
>Address : Neupaoer Str. 1
>Phone : 073/880755
>Name : Valeri lItov lItov - Cadr
>Name : Nikoilai Michev Michev
>Name : Silvia Mold
>
>I will have mysql databse with fields like
>CONTACT , MANAGER, STATE , CODE, City, Adress , Name
>I will split data on : and insert it into database but i can't find a
>way how to combine this duplicate Filed Name
>like NAME : Valeri lItov lItov - Cadr, Nikoilai Michev Michev,Silvia Mold
>Can anybody give mo some idea how to combine these duplicating name
>records into one record.
>
Hello,
How about using this data stru to store the date fields?
%hash = ( 'CODE' => [
'4005'
],
'Name' => [
'Valeri lItov lItov - Cadr',
'Nikoilai Michev Michev',
'Silvia Mold'
]
...
);
This is the code piece I wrote,it can work.
use strict;
use warnings;
my %hash;
open FILE,"data.txt" or die $!;
while(<FILE>) {
next if /^$/;
chomp;
my ($fname,$fvalue) = split/:/;
$fname =~ s/^\s+|\s+$//g;
$fvalue =~ s/^\s+|\s+$//g;
push @{$hash{$fname}},$fvalue;
}
close FILE;
for (keys %hash) {
print $_ , "-->", join ', ',@{$hash{$_}};
print "\n";
}
--
mailto: [EMAIL PROTECTED]
http://home.arcor.de/jeffpang/
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/