The usage of Perl variable $/when parsing context is row mode, what $/defines to distinguish line _ application Tips

Source: Internet
Author: User
By default, it is clear that the rows are distinguished by \ n, which we also call as line breaks.
When reading a sequence, when read by row, the line break is the standard.

The contents of the read STRAWBERRY1.GB 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 Code code as follows:

#!/bin/perl
my $record = ';
Open (Dnafilename, ' F:\\PERL\\STRAWBERRY1.GB ') | | Die ("Can not open the file!");
$record = <DNAFILENAME>;
Print $record;


This is the case without any changes, and is the default read one line at a time, the result is as follows:
f:\>perl\b.pl
Locus JX118024 460 bp DNA linear PLN 25-sep-2012

If we change the value of $/, according to the characteristics of our documents, we first change to $/= "///\n;

Copy Code code as follows:

#!/bin/perl
my $record = ';
Open (Dnafilename, ' F:\\PERL\\STRAWBERRY1.GB ') | | Die ("Can not open the file!");
$/= "///\n";
$record = <DNAFILENAME>;
Print $record;


We have the following results:
f:\>perl\b.pl
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 delimited by///, and that the entire part of///is considered a row.

The same is not only the character can be used as a separator, letters can also join us to how the separator, $/= "how\n";

Copy Code code as follows:

#!/bin/perl
my $record = ';
Open (Dnafilename, ' F:\\PERL\\STRAWBERRY1.GB ') | | Die ("Can not open the file!");
$/= "how\n";
$record = <DNAFILENAME>;
Print $record;


The results are as follows:
C:\Documents and settings\administrator>f:perl\b.pl
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>

Also, we can completely discard the traditional lines, for example, we use the accession in the fifth row of the example as delimiters:

Copy Code code as follows:

#!/bin/perl
my $record = ';
Open (Dnafilename, ' F:\\PERL\\STRAWBERRY1.GB ') | | Die ("Can not open the file!");
$/= "accession";
$record = <DNAFILENAME>;
Print $record;


The results are as follows:
f:\>perl\b.pl
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:\>

One more example: Take/\n as the separator:

Copy Code code as follows:

#!/bin/perl
my $record = ';
Open (Dnafilename, ' F:\\PERL\\STRAWBERRY1.GB ') | | Die ("Can not open the file!");
$/= "/\n";
$record = <DNAFILENAME>;
Print $record;


We expect the result to be one row for the previous row to line fourth, but is this the result?
f:\>perl\b.pl
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 it match up to the first one?

In fact here/this line does not have only one/, but there are other components here, we put this line completely deleted, and then re-enter only one/, we again to match
f:\>perl\b.pl
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 get the right results.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.