Hello raghuprasad241, I have a different approach for you. Previously, due to some hole in your input data that i have to go through all the trouble to make that big code. Now you have a much nicer input so we can make it look like this.

#!/usr/bin/perl use v5.10; use strict; use warnings; sub tranpose(@); my @row; my @sorted; while(my $line = <DATA>) { push @row, [split(/\s+/,$line)]; } @sorted = map { my $in = $_; [map {sprintf("%6s",$_)} @$in]; } #Reformat before prin +t tranpose #tranpose back to ori +ginal form map {[sort {$a <=> $b} @$_]} #sort each column tranpose @row; map {print @$_,"\n"} @sorted; sub tranpose(@) { my @out; foreach my $j (0..$#{$_[0]}) { push @out, [map {$_[$_][$j]} (0..$#_)]; } @out; } __DATA__ 1014 1 10 1015 51 100 1016 11 50 1017 101 999

Output:

1014 1 10 1015 11 50 1016 51 100 1017 101 999

Hope this help!


In reply to Re^3: Sorting a matrix based on the values of columns by redbull2012
in thread Sorting a matrix based on the values of columns by raghuprasad241

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.