Several ways of processing Perl file reads summary _perl

Source: Internet
Author: User

1, single line (large file processing):

Copy Code code as follows:

My $oneline = < $FL > or
while ($line ={ }

2, read all (small file processing):

Copy Code code as follows:

Open (My $in, "path") or Die "Open error: $!";
My @lines = < $in >;

3, read 3 lines (large files and special processing needs):

Copy Code code as follows:

Open (My $in, "path") or Die "Open error: $!";
My @lines;
Push (@lines, scalar < $in >) for (1..3);

4. Read three lines per condition and two lines according to condition. or modify according to other specific requirements to achieve the corresponding purpose.

Copy Code code as follows:

while (<TEST>) {
if (Index ($_, "=") >-1) {
My $position =tell (TEST);
My $keyword _line=$_;
My $line _1=<test>;
My $line _2=<test>;
# @a=split//, $keyword _line; Compare their elements to be equal, never succeeded
# @b=split//, $line _1; Use if ($a [0]eq $a [0]) to determine
# @c=split//, $line _2;
if ($line _2) && (Index ($line _2, "=") >-1)) {# or if ($line _2=~/=/)
Print outfile "$_$line_1";
}
if (!) ( $line _2)) {print outfile "$_$line_1"; last;}
Seek (TEST, $position, 0);
}
}

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.