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.


My 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?

Perl script

# 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 );

Extract Part of a FASTA Sequences with Position by python script HERE


What will happen if you replace '@' with '$' in line 13 

No comments:

Post a Comment

Have Problem ?? Drop a comments here!