hello99hello
Programmer
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.
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.