User Tools

Site Tools


tutorials:perl_exercises

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tutorials:perl_exercises [2010/08/03 11:49] chkuotutorials:perl_exercises [2010/08/07 00:42] (current) chkuo
Line 61: Line 61:
 </code> </code>
 See a sample answer [[tutorials:perl:count_first_name.pl|here]]. See a sample answer [[tutorials:perl:count_first_name.pl|here]].
 +
 +===== write_lines_to_files =====
 +Obtain an input file and an output directory from the command line. Produce one output file for each line in the input file, use the line number (i.e., 1, 2, 3, etc) as the filenames.
 +
 +**Hint: learn about filehandle and directory operation before attempting this exercise.**
 +
 +<code bash>
 +$ cat input.txt 
 +George Washington
 +John Adams
 +Thomas Jefferson
 +James Madison
 +James Monroe
 +$ perl write_lines_to_files.pl input.txt output/
 +$ head output/*
 +==> output/1 <==
 +George Washington
 +
 +==> output/2 <==
 +John Adams
 +
 +==> output/3 <==
 +Thomas Jefferson
 +
 +==> output/4 <==
 +James Madison
 +
 +==> output/5 <==
 +James Monroe
 +</code>
 +See a sample answer [[tutorials:perl:write_lines_to_files.pl|here]].
 +
 +
 +===== combine_files =====
 +The opposite of write_lines_to_files; obtain an input directory and an output file from the command line, read the files in the input directory and write their content to one single output file. Note that we want to exclude hidden files in the input directory.
 +
 +**Hint: learn about filehandle, directory operation, and pattern matching before attempting this exercise.**
 +
 +<code bash>
 +$ head output/*
 +==> output/1 <==
 +George Washington
 +
 +==> output/2 <==
 +John Adams
 +
 +==> output/3 <==
 +Thomas Jefferson
 +
 +==> output/4 <==
 +James Madison
 +
 +==> output/5 <==
 +James Monroe
 +$ perl combine_files.pl output/ combined.txt
 +$ cat combined.txt 
 +George Washington
 +John Adams
 +Thomas Jefferson
 +James Madison
 +James Monroe
 +</code>
 +See a sample answer [[tutorials:perl:combine_files.pl|here]].
 +
 +
  
 ===== unwrap_fasta ===== ===== unwrap_fasta =====
Line 133: Line 198:
 </code> </code>
 See a sample answer [[tutorials:perl:count_EcoRI_site.pl|here]]. See a sample answer [[tutorials:perl:count_EcoRI_site.pl|here]].
 +
 +
tutorials/perl_exercises.1280807399.txt.gz · Last modified: by chkuo