A couple of minor nits:
I personally try to avoid using subscripts in favor of assigning a name to variables in a split.
In this case, I'm not sure what the number represents (or the name), I'm sure the OP knows better a better description than us.
I would use a push instead of array assignment to @ordered, just because it seems more natural to me.
This is minor stuff - no problem at all with your code.
Update: I guess I don't know what is supposed to happen if say YOUSLAV appeared twice for 20055111 or whether that is even possible to occur. If that is possible, the OP should clarify.
#! perl -slw use strict; use Data::Dump qw[ pp ]; my( @ordered, %grouped ); while( <DATA> ) { chomp; my ($number, $name) = split ',', $_; push (@ordered, $number ) unless exists $grouped{$number }; push @{ $grouped{ $number } }, $name; } #pp \@ordered, \%grouped; print "$_|", join ',', @{ $grouped{ $_ } } for @ordered; =prints 20055111|YOUSLAV,YURT,TENWIMPL 20011271|YOUSLAV,WUMARTHE 20011541|YOUSLAV,TENWIMPL 20102741|WEDLOFOU,YOUSLAV,YURT,KUPLYSO,TENWIMPL 20155505|YOUSLAV,YURT,TENWIMPL 20147155|YOUSLAV,KUPLYSO,FRIMA =cut __DATA__ 20055111,YOUSLAV, 20055111,YURT, 20055111,TENWIMPL, 20011271,YOUSLAV, 20011271,WUMARTHE 20011541,YOUSLAV, 20011541,TENWIMPL, 20102741,WEDLOFOU, 20102741,YOUSLAV, 20102741,YURT, 20102741,KUPLYSO, 20102741,TENWIMPL, 20155505,YOUSLAV, 20155505,YURT, 20155505,TENWIMPL, 20147155,YOUSLAV, 20147155,KUPLYSO, 20147155,FRIMA,
In reply to Re^2: How do I remove duplicate numeric elements of an array and preserve alphabetic elements?
by Marshall
in thread How do I remove duplicate numeric elements of an array and preserve alphabetic elements?
by jzelkowsz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |