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
In reply to difficulty in multi sorting by texuser74
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |