in reply to How do I remove duplicate numeric elements of an array and preserve alphabetic elements?

Do not think of your problem as removing numeric data. Look at the problem as one of combining all the alpha data that belongs to the same numeric 'key'. In this view, store the data as a hash-of-arrays with the numbers as the keys.
use strict; use warnings; use Autodie; open my $FH, '<', 'jzelkowsz.dat'; my %data; while (my $pair = do{ $/ = ', ';<$FH>}) { my ($numeric, $alpha) = split qr/,/, $pair; push @{$data{$numeric}}, $alpha; } foreach my $num (sort keys %data) { $" = ','; $\ = "\n"; print "$num|@{$data{$num}}"; }
Bill
  • Comment on Re: How do I remove duplicate numeric elements of an array and preserve alphabetic elements?
  • Download Code

Replies are listed 'Best First'.
Re^2: How do I remove duplicate numeric elements of an array and preserve alphabetic elements?
by jzelkowsz (Novice) on Jun 07, 2018 at 13:25 UTC
    Thank you, Bill. I appreciate a different way of looking at the problem.