Code for perl to sort m x n similar tables by Column

Source: Internet
Author: User

Operations such as csv are frequently encountered in perl processing files. Such a table is similar to a two-dimensional array, so operations on the two-dimensional array are actually performed.
For such a row and column table, we often need to sort by a column or by a column first and then by another column. Here we paste the perl implementation to facilitate the next query.

See the following code.

Copy codeThe Code is as follows :#! /Usr/bin/perl
My @ line;
While (<>)
{
Chomp;
Push @ line, [split];
}
Foreach (sort {$ a-> [0] <=> $ B-> [0] or $ a-> [1] <=> $ B-> [1] or $ a-> [2] <=> $ B-> [2]} @ line)
{
Print @ $ _, "\ n ";
}

Note:
It is best not to use large files in this way.
This script will move all the data to the memory.

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.