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 MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File Processing Help 1

Status
Not open for further replies.

hello99hello

Programmer
Jul 29, 2004
50
CA
Hello All,

I have to say I am still a biginner in Perl.

I am writting a script to fetch a file(input_file), read each record(file_record)from the file. Manipulate some fields in the file_record and write the result to another file.

Here is my effort:

#check if file exist
if (-e "input_file.txt){
print "the file exist \n" ;
}else{
Print "The file does not exsit\n";
#opean the file, and read each record into array
open (INPUT, "$input_file"){
print "file opeaned \n" ;
}else{
Print "Could not opean file\n";
open (OUTPUT, ">$output_file"){
print "outfile opeaned \n" ;
}else{
Print "Could not opean outfile\n";
#while file opean, read each element of the array and maniplate.
while (<INPUT>){
@array_record=$input_record
if $array_record[2]!= M {
print "record is not male, and it to be changed\n" ;
}else{
$arra_record[2] = M
Print "record is now $arra_record[2]\n";
}
#write new record to uput file
print OUTPUT $.= <$_>\n ;}

close (INPUT);
close (OUTPUT);


However, I am having problem actualizing my intention

could anyone help.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top