Hi, Be careful with the "sort keys %unique" because if the list is bigger like that :
__DATA__ 1 a 2 b 2 c 3 a 4 d 4 d 4 e 4 f 5 g 8 f 10 e 10 y you will get : 1 a 10 e,y <== I don't think you are looking for that , no ? 2 b,c 3 a 4 d,e,f 5 g 8 f Look at the "perldoc -f sort" to have the numerical order Michel -----Message d'origine----- De: Marcus Claesson [mailto:[EMAIL PROTECTED] Date: jeudi 18 septembre 2003 11:56 À: Thomas Bätzler Cc: [EMAIL PROTECTED] Objet: RE: list-parsing problem Homework's sorted ;)! Thanks a lot Thomas, it worked fine! Marcus On Thu, 2003-09-18 at 10:41, Thomas Bätzler wrote: > Marcus Claesson [mailto:[EMAIL PROTECTED] asked: > > I have a silly little list-parsing problem that I can't get my head > > around, and I'm sure some of you have come across it before. > > Sure. Looks like homework ;-) > > HTH, > Thomas > > #!/usr/bin/perl -w > > use strict; > > my %unique; > > while( <DATA> ){ > my( $key, $value ) = split; > > $unique{$key}->{$value}++ > } > > foreach my $key ( sort keys %unique ){ > print "$key: " . join( ", ", sort keys %{$unique{$key}} ) . "\n"; > } > > __DATA__ > 1 a > 2 b > 2 c > 3 a > 4 d > 4 d > 4 e > 4 f > 5 g -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]