How to Open and Write Data to a File with PERL
Yesterday I learn to write data to a file with the help of PERL. Today I will discuss about how to open a file, read this and finally write the response to another file. Today's PERL script is very similar to yesterday one except few modification. Here in first couple of line, we will open the file and then print its content. After that we will store the input provided by user and, then, in the last few line we will write the user's response in another file. In another words, we will ask some questions from users and then write the response in a file.
INPUT FILEMy input file has following question
Question 1 : What is your name? Question 2 : In what city do you live? Question 3 : What is one of your hobbies?
#!/usr/local/bin/perl # This line will ask for name of your file print "Write the name of your file? \n"; # Name of your file will be store in $input_file $input_file = <>; # Your file will be open here open (FILE, $input_file); # All content of Your file will be stored in @print_input_file @print_input_file = <FILE>; # This line will print the data store in our input file print "@print_input_file"; # This line will make a file 'result.txt' to store your answer open (OUT, ">result.txt"); # This line will store the answer of question 1 print "Answer your question 1? \n"; $answer1 = <>; # This line will store the answer of question 2 print "Answer your question 2? \n"; $answer2 = <>; # This line will store the answer of question 3 print "Answer your question 3? \n"; $answer3 = <>; # This line will store all your answer into @answer @answer = ($answer1, $answer2, $answer3); # This line will print all your answer into file 'result.txt' print (OUT @answer );
What will happen if you replace '@' with '$' in line 13
First of all, let me clear it that i am not a Bioinformatician. i am simple plant biology researcher who face problem in her daily research life and who bother to post solution of those problem on this webpage. That's it.
Labels: Learn PERL