By default, it is obvious that \n is used to distinguish lines, and \n is also called a newline character.
When reading a sequence and reading by line, the newline character is used as the standard.
The contents of the read file are as follows:
LOCUS JX118024 460 bp DNA linear PLN 25-SEP-2012
DEFINITION Fragaria vesca subsp. americana RNA polymerase beta subunit (rpoC1)
gene, partial cds; plastid.
/
ACCESSION JX118024
//
VERSION JX118024.1 GI:402238751
KEYWORDS .
how
///
SOURCE plastid Fragaria vesca subsp. americana
First example: default
#!/bin/perl
my $record =' ';
open (DNAFILENAME,'f:\\perl\\')||die("can not open the file!");
$record = <DNAFILENAME>;
print $record;
This is the case without any changes, which means that one line is read by default, and the result is as follows:
F:\>perl\
LOCUS JX118024 460 bp DNA linear PLN 25-SEP-2012
If we change the value of $/, according to the characteristics of our file, we first change it to $/="///\n;
#!/bin/perl
my $record =' ';
open (DNAFILENAME,'f:\\perl\\')||die("can not open the file!");
$/="///\n";
$record = <DNAFILENAME>;
print $record;
The results we get are as follows:
F:\>perl\
LOCUS JX118024 460 bp DNA linear PLN 25-SEP-2012
DEFINITION Fragaria vesca subsp. americana RNA polymerase beta subunit (rpoC1)
gene, partial cds; plastid.
/
ACCESSION JX118024
//
VERSION JX118024.1 GI:402238751
KEYWORDS .
how
///
We can see here that this line is based on // as the separator, and the entire part above is regarded as a line.
Also, not only characters can be used as delimiters, but also letters can be used. Add to us how as delimiters, $/="how\n";
#!/bin/perl
my $record =' ';
open (DNAFILENAME,'f:\\perl\\')||die("can not open the file!");
$/="how\n";
$record = <DNAFILENAME>;
print $record;
The results are as follows:
C:\Documents and Settings\Administrator>f:perl\
LOCUS JX118024 460 bp DNA linear PLN 25-SEP-2012
DEFINITION Fragaria vesca subsp. americana RNA polymerase beta subunit (rpoC1)
gene, partial cds; plastid.
/
ACCESSION JX118024
//
VERSION JX118024.1 GI:402238751
KEYWORDS .
how
C:\Documents and Settings\Administrator>
Similarly, we can completely abandon lines in the traditional sense. For example, we use the fifth line of the example as the delimiter:
#!/bin/perl
my $record =' ';
open (DNAFILENAME,'f:\\perl\\')||die("can not open the file!");
$/="ACCESSION";
$record = <DNAFILENAME>;
print $record;
The results are as follows:
F:\>perl\
LOCUS JX118024 460 bp DNA linear PLN 25-SEP-2012
DEFINITION Fragaria vesca subsp. americana RNA polymerase beta subunit (rpoC1)
gene, partial cds; plastid.
/
ACCESSION
F:\>
Let’s take another example: use /\n as the delimiter:
#!/bin/perl
my $record =' ';
open (DNAFILENAME,'f:\\perl\\')||die("can not open the file!");
$/="/\n";
$record = <DNAFILENAME>;
print $record;
The result we expect should be that the content before the fourth line should be one line, but is this the result?
F:\>perl\
LOCUS JX118024 460 bp DNA linear PLN 25-SEP-2012
DEFINITION Fragaria vesca subsp. americana RNA polymerase beta subunit (rpoC1)
gene, partial cds; plastid.
/
ACCESSION JX118024
//
F:\>
Why didn't the first / match?
In fact, there is not just one / in this line here, but there are other components here. We completely delete this line, and then enter only one / again, and we will match it.
F:\>perl\
LOCUS JX118024 460 bp DNA linear PLN 25-SEP-2012
DEFINITION Fragaria vesca subsp. americana RNA polymerase beta subunit (rpoC1)
gene, partial cds; plastid.
/
F:\>
This time we got the correct result.
When reading a sequence and reading by line, the newline character is used as the standard.
The contents of the read file are as follows:
LOCUS JX118024 460 bp DNA linear PLN 25-SEP-2012
DEFINITION Fragaria vesca subsp. americana RNA polymerase beta subunit (rpoC1)
gene, partial cds; plastid.
/
ACCESSION JX118024
//
VERSION JX118024.1 GI:402238751
KEYWORDS .
how
///
SOURCE plastid Fragaria vesca subsp. americana
First example: default
Copy the codeThe code is as follows:
#!/bin/perl
my $record =' ';
open (DNAFILENAME,'f:\\perl\\')||die("can not open the file!");
$record = <DNAFILENAME>;
print $record;
This is the case without any changes, which means that one line is read by default, and the result is as follows:
F:\>perl\
LOCUS JX118024 460 bp DNA linear PLN 25-SEP-2012
If we change the value of $/, according to the characteristics of our file, we first change it to $/="///\n;
Copy the codeThe code is as follows:
#!/bin/perl
my $record =' ';
open (DNAFILENAME,'f:\\perl\\')||die("can not open the file!");
$/="///\n";
$record = <DNAFILENAME>;
print $record;
The results we get are as follows:
F:\>perl\
LOCUS JX118024 460 bp DNA linear PLN 25-SEP-2012
DEFINITION Fragaria vesca subsp. americana RNA polymerase beta subunit (rpoC1)
gene, partial cds; plastid.
/
ACCESSION JX118024
//
VERSION JX118024.1 GI:402238751
KEYWORDS .
how
///
We can see here that this line is based on // as the separator, and the entire part above is regarded as a line.
Also, not only characters can be used as delimiters, but also letters can be used. Add to us how as delimiters, $/="how\n";
Copy the codeThe code is as follows:
#!/bin/perl
my $record =' ';
open (DNAFILENAME,'f:\\perl\\')||die("can not open the file!");
$/="how\n";
$record = <DNAFILENAME>;
print $record;
The results are as follows:
C:\Documents and Settings\Administrator>f:perl\
LOCUS JX118024 460 bp DNA linear PLN 25-SEP-2012
DEFINITION Fragaria vesca subsp. americana RNA polymerase beta subunit (rpoC1)
gene, partial cds; plastid.
/
ACCESSION JX118024
//
VERSION JX118024.1 GI:402238751
KEYWORDS .
how
C:\Documents and Settings\Administrator>
Similarly, we can completely abandon lines in the traditional sense. For example, we use the fifth line of the example as the delimiter:
Copy the codeThe code is as follows:
#!/bin/perl
my $record =' ';
open (DNAFILENAME,'f:\\perl\\')||die("can not open the file!");
$/="ACCESSION";
$record = <DNAFILENAME>;
print $record;
The results are as follows:
F:\>perl\
LOCUS JX118024 460 bp DNA linear PLN 25-SEP-2012
DEFINITION Fragaria vesca subsp. americana RNA polymerase beta subunit (rpoC1)
gene, partial cds; plastid.
/
ACCESSION
F:\>
Let’s take another example: use /\n as the delimiter:
Copy the codeThe code is as follows:
#!/bin/perl
my $record =' ';
open (DNAFILENAME,'f:\\perl\\')||die("can not open the file!");
$/="/\n";
$record = <DNAFILENAME>;
print $record;
The result we expect should be that the content before the fourth line should be one line, but is this the result?
F:\>perl\
LOCUS JX118024 460 bp DNA linear PLN 25-SEP-2012
DEFINITION Fragaria vesca subsp. americana RNA polymerase beta subunit (rpoC1)
gene, partial cds; plastid.
/
ACCESSION JX118024
//
F:\>
Why didn't the first / match?
In fact, there is not just one / in this line here, but there are other components here. We completely delete this line, and then enter only one / again, and we will match it.
F:\>perl\
LOCUS JX118024 460 bp DNA linear PLN 25-SEP-2012
DEFINITION Fragaria vesca subsp. americana RNA polymerase beta subunit (rpoC1)
gene, partial cds; plastid.
/
F:\>
This time we got the correct result.