program demonstrates how to read
contents from a file. Here we first define a scalar variable with a null
value and provide the name of the file in $krupa.seq. If the file is located in
the same directory where the Perl program is located then we need not specify
the full path, else we need to specify full path of the file.
the file we use a command called “open”. The “FILE” here is the file handler.
The $krupa.seq contains the file name to be opened. The file is read by using
the file handler.
reads the first line in the file and stores it in the variable $dna. Here the
whole line is saved as one value as the variable is a scalar. If the variable
was an array, all the lines would have been read and each line would have been
saved as one value in the array. This <FILE> operation is used in the
while loop to read all the lines of the file in a sequence. Once the line is
read and stored in $dna, we perform a chomp
on the variable to remove the trailing character (enter symbol). We now concatenate the value with the existing
value of $longdna and save the whole result again in $longdna. Therefore it
should be written as
it short we write it as
we have reduced it by putting “.=” which
means concatenate the two values and save the result to the left hand side
variable. The same is with “+=” for addition and other mathematical operations.
every line is read, chomp and concatenated the variable $longdna contains the
complete result which is printed on to the screen. The while loop ends when
there are no more lines to be read, that is it has reached to the end of the
- #filehandler and nullstring
- close FILE;
is the dna:$longdna:\n\n";
here is the