Welcome to biology-online.org! Please login to access all site features. Create an account.
Log me on automatically each visit
Perl script is designed to visualize virtually the features of nucleotide strings. …
Biology Articles » Bioinformatics » Introductory Workbook on Perl for Biology Students » 5. Perl Program for File handling For Scalar And Array Variables
program shows the difference in results
in using scalar variables and array variables in retrieving data from a file.
We first assign a file name to a scalar variable ($DNA) for our program. We
then use the open command to open the file. The command <dna1> reads the
first line of the file and stores the value in the scalar variable $DNA2. A
scalar variable can hold only one value at a time and hence the next lines of
the file are not stored in the variable instead it skips to the next line where
the close command is issued. So the variable $DNA2 contains only the first line
of the file.
test is to use an array. In line 9, the first line of the file is read and
stored in the array variable @DNA2. Since the variable is an array all the
lines from the file can be read and stored into this array. Each line would be
stored as one value of the array. Once the file is read completely the program
goes to the next line where the file is closed.
now like to join all the values of the array $DNA2 into one complete string.
For that we would first need to remove the “enter”
character at the end of each value of the array. The enter character appears
each time we hit the enter key on our keyboard while writing to a file. This
enter character is invisible. As all the lines are copied into the array, the
values also contain this enter character. So we first remove this character by
using chomp on the array. Now the
array is free of the enter character. We will now join the values of the array
by using a command called “join”.
The values of the array are joined based on ‘null’ (‘’ without any space between
the quotes) as quoted
in line 16. Hence there would be no
value add between the values of the array. We now get one complete string from
the values of the array and are stored in $DNA3. We find out the length of this
variable by using a command called “length”.
the sequence of
the sequence of two strings
the results of chomp
the result of join of two
the length of two strings of
rating: 3.70 from 116 votes | updated on: 30 Jan 2009 | views: 105824 |
share this article | email to friends
suggest a revision
print this page
print the whole article
© Biology-Online.org. All Rights Reserved. Register | Login | About Us | Contact Us | Link to Us | Disclaimer & Privacy