Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

file pointer

Status
Not open for further replies.

whygh

Programmer
Apr 18, 2005
16
CA
Good Morning Everyone,

I did a very simple perl program, donot laugh at me.

####
open(USERFILE,"<test1.txt")||die "can't open this file! :$!";
open(USERINFO,">userinfo.txt")||die "can't open this file! :$!";
do{
$name=<USERFILE>;
chomp($name);

if($name="01001") {
$user=<USERFILE>;
chomp($user);
$position=index($user,":")+1;
$user=substr($user,$position);

$pass=<USERFILE>;
chomp($pass);
$position1=index($pass,":")+1;

$pass=substr($pass,$position1);

$phone=<USERFILE>;
chomp($phone);
$position2=index($phone,":")+1;
$phone=substr($phone,$position2);

$address=<USERFILE>;
chomp($address);
$position3=index($address,":")+1;
$address=substr($address,$position3);
}
else {
$end=<USERFILE>;

}
print USERINFO ("$user $pass $phone $address\n");
}while(!(eof));

close USERFILE;
close USERINFO;
####
test1.txt :
01001
Use1:52 PM 4/25/2005rID:001
PassWd:qwerr
Phone:123456789
Address:123 room
01000
01001
UserID:002
PassWd:qweqq
Phone:123456000
Address:124 room
01000
01001
UserID:003
PassWd:asdfg
Phone:500123456
Address:125 room
01000

I want to output like this:
001 qwerr 123456789 123 room
002 qweqq 123456000 124 room
003 asdfg 500123456 125 room

But I got the result like this:
001 qwerr 123456789 123 room
01001 001 qwerr 123456789
01000 01001 001 qwerr
123 room 01000

what's wrong with this program?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top