Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

numbers OK; Re: sorting comma separated value file

by tye (Sage)
on Aug 22, 2000 at 22:04 UTC ( [id://29070]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    #!/usr/bin/perl -w
    use strict;
    ...
    my @sort= map { my $x=join"\0"x5,(split/\s*,\s*/)[@cols];
            $x =~ s/(^|[^\d.])(\d+)/$1.pack("N",$2)/eg; $x } @lines;
    print @lines[  sort { $sort[$a] cmp $sort[$b] } 0..$#sort  ];
    
  2. or download this
    die "Usage: $0 col[,col[...]] [file[,...]]\n" unless @ARGV;
    my @cols= map { $_-1 } split/,/,shift;
    ...
        sort { $a->[0] cmp $b->[0] }
            map { my $x=join"\0\0\0\0",(split/\s*,\s*/)[@cols];
              s/(^|[^\d.])(\d+)/$1.pack("N",$2)/eg; [$x,$_] } <>;
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://29070]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-25 17:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found