CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Data trouble

 



perlkid
stranger

Mar 20, 2000, 10:12 AM

Post #1 of 5 (848 views)
Data trouble Can't Post

 
Hi Everyone.

Can Someone please help me with this code. It's supposed to take the second field in one data base and print it in the place of field1 in the second data base and visa versa. It is supposed to simply switch the first field with the second field and print the new format to a new database.

here's the code
###################
open(FILE,">$german1");
open(F,"$german");
@search=<F>;
close(F);
$count=0;
foreach $res (@search) {
$count++;
@records=split(/\|/,$res);
print FILE "$records[1]|$records[0]";
}
close(FILE);
print "Done";
##################################

This is what the data looks like in $german
#####

aardvark|Erdferkel
aardvarks|Erdferkel
aback|ru.ckwa.rts
abacterial|abakteriell
abacus|Abakus
abacuses|Abakus
abaft|nach achtern
abalone|Pfahlmuschel
abalones|Pfahlmuscheln
abandon|aufgeben
abandon|aussetzen
abandon|verlassen
abandon|verlassen
abandoned|verlassen

####################

and the output in $german1 looks like this after running that code.

#########

Erdferkel
|aardvarkErdferkel
|aardvarksru.ckwa.rts
|abackabakteriell
|abacterialAbakus
|abacusAbakus
|abacusesnach achtern
|abaftPfahlmuschel
|abalonePfahlmuscheln
|abalonesaufgeben
|abandonaussetzen
|abandonverlassen
|abandonverlassen
|abandonverlassen
|abandoned


#########

Can Someone please help, I've been going at this for about 7 hours now.

Thank you So Much,

perlkid


perlkid
stranger

Mar 19, 2000, 10:57 PM

Post #2 of 5 (848 views)
Re: Data trouble [In reply to] Can't Post

 That is the whole code, the problem is that when I run the code the output into the $german1 file is not in the format I was aiming for.

Here's what It's doing, In the File german.db the file is in this format;

aardvark|Erdferkel

The Engilsh word is on the left and the German word is on the right.

The code is supposed to switch the fields so that the German Word is in front of the English word instead. And then print the code to german1.db which is different from the file that is read Like This,

Erdferkel|aardvark

But when I run this script I open up the german1.db and it looks like this,


|aardvarkErdferkel

It's like it switches the words but it leaves out the pipe that is supposed to be between aardvark and Erdferkel and places it in front of the two fields.

I hope I'm not being too confusing,

Thanks Cretep,

I'm also not getting server 500 errors,



[This message has been edited by perlkid (edited 03-20-2000).]


Cretep
User

Mar 20, 2000, 5:13 AM

Post #3 of 5 (848 views)
Re: Data trouble [In reply to] Can't Post

Hi
Can you post the entire script also what is it doing wrong i.e. returning a 500 or just refusing to cooperate.

Regards

Peter Crouch


Cure
User

Mar 20, 2000, 1:04 PM

Post #4 of 5 (848 views)
Re: Data trouble [In reply to] Can't Post

Hi

This is will work for you::

open(F,"<$german");
open(FILE,">$german1");

while (<F> ) {

($cure,$you)=(split(/\|/,$_));

$you=join('|',$you,$cure);

print FILE $you;
}

close(F);
close(FILE);
print "Done";


Cure


perlkid
stranger

Mar 21, 2000, 12:45 AM

Post #5 of 5 (848 views)
Re: Data trouble [In reply to] Can't Post

 
Thanks Cure,

I'll try that tonight!

Thanks,

perlkid

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives