texuser74 has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks
I want to do two types of sorting in the follwoing input data, e.g.
1st sort: Sort the names, and then combine them:Input:<test.in> Xu, Guo Qin B-5-OR9 Zhang, Yong Ping B-5-OR10 Xu, Guo Qin B-5-OR10 Tsuneyuki, Shinji B-6-IN11 Xu, Guo Qin B-6-IN12
2nd Sort: This is where i am having problem, now i want to sort the codes numerically inside each name, i.e. the required output isopen(IN, '<', "test.in"); open(OUT, '>', "test.out"); while (<IN>) { chomp; next unless /\S/; my ($name, $num) = /(.*)\s+(B-.*)/; $data{$name}{$num} = 1; } foreach my $name (sort keys %data) { print OUT "$name "; print OUT join ', ', sort { $a cmp $b } keys %{$data{$name}}; print OUT "\n\n"; } output: Tsuneyuki, Shinji B-6-IN11 Xu, Guo Qin B-5-OR10, B-5-OR9, B-6-IN12 Zhang, Yong Ping B-5-OR10
please help me in doing this.Tsuneyuki, Shinji B-6-IN11 Xu, Guo Qin B-5-OR9, B-5-OR10, B-6-IN12 Zhang, Yong Ping B-5-OR10
best regards,
raj
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: difficulty in multi sorting
by jdporter (Paladin) on May 19, 2005 at 04:55 UTC | |
Re: difficulty in multi sorting
by pelagic (Priest) on May 19, 2005 at 06:34 UTC |
Back to
Seekers of Perl Wisdom