Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Sorting text files.

by Tux (Canon)
on Nov 08, 2015 at 12:09 UTC ( [id://1147201]=note: print w/replies, xml ) Need Help??


in reply to Sorting text files.

Nice one. I could not resist doing that in Text::CSV_XS' csv function (this won't fly if your file is huge):

use 5.20.0; use warnings; use Text::CSV_XS qw(csv); my $n = 1; open my $fh, "<", "file2.txt"; my %sort = map { chomp; $_ => $n++ } <$fh>; close $fh; csv (sep => ";", before_out => sub { shift @{$_[1]} }, quote_space => +0, in => [ sort { $a->[0] <=> $b->[0] } @{csv (sep => ";", in => *DA +TA, after_parse => sub { unshift @{$_[1]}, $sort{$_[1][0]} // $n })}] +, ); __END__ 1 HD;BSkyB:11097:VC23M5O25P0S1:S28.2E:23000:2305=27:2307=NAR@4;2306=en +g@106:2308;2309=eng:0:21000:2:2066:0 2 HD;BSkyB:11097:VC23M5O25P0S1:S28.2E:23000:2315=27:2316=NAR@4;2317=en +g@106:2318;2319=eng:0:21020:2:2066:0 3 HD;BSkyB:11097:VC23M5O25P0S1:S28.2E:23000:2320=27:2321=NAR@4;2322=en +g@106:2323;2324=eng:0:21030:2:2066:0 ITV HD;BSkyB:11097:VC23M5O25P0S1:S28.2E:23000:2305=27:2307=NAR@4;2306= +eng@106:2308 => 3 HD;BSkyB:11097:VC23M5O25P0S1:S28.2E:23000:2320=27:2321=NAR@4;2322=en +g@106:2323;2324=eng:0:21030:2:2066:0 1 HD;BSkyB:11097:VC23M5O25P0S1:S28.2E:23000:2305=27:2307=NAR@4;2306=en +g@106:2308;2309=eng:0:21000:2:2066:0 2 HD;BSkyB:11097:VC23M5O25P0S1:S28.2E:23000:2315=27:2316=NAR@4;2317=en +g@106:2318;2319=eng:0:21020:2:2066:0 ITV HD;BSkyB:11097:VC23M5O25P0S1:S28.2E:23000:2305=27:2307=NAR@4;2306= +eng@106:2308;2309=eng:0:21000:2:2066:0

Enjoy, Have FUN! H.Merijn

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-03-28 18:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found