in reply to Trying to write simple program
The clustering you describe can be accomplished using the description as a key in a hash of arrays - see perllol. Something like this:
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %hash; while (my $line = <DATA>) { chomp $line; my ($number, $description) = split /\s/, $line, 2; push @{$hash{$description}}, $number; } print Dumper \%hash; __DATA__ 00001 Description1 00002 Description2 00003 Description1
See perlreftut if you are not familiar with references. Let us know if you have trouble changing this code into something that outputs your desired format.
|
|---|