in reply to Re: Re: Text Manipulation Quickie
in thread Text Manipulation Quickie
But you're still not defining the question in any manner that we can accurately extrapolate what you're trying to do. Especially when you use the word sort. We define sort to put all occurances of 2 before occurances of 3, before 4. So what you're asking us to do is unsort the data. There are an infinite number of ways of doing so, which result in arbitrary orderings (although the are only n! such orderings).
Most of the solutions suggested simply counted the number of 2s, 3s and 4s (etc), and then repeatedly printed one of each (in ascending order) as long as necessary: they were actually discarding the original data.
What it seems like you're after is
which is, essentially, just a variation of that theme.foreach (<DATA>) { ($key, $val)=split ';', $_, 2; push @{$store{$key}}, $val; } while (keys %store) { foreach $key (sort keys %store) { print join ';', $key, shift @{$store{$key}}; delete $store{$key} unless scalar @{$store{$key}}; } } __DATA__ 2;3425; 2;4534; 2;2155; 3;1324; 3;1253; 3;3455; 4;3454; 4;3464; 4;3454;
The answer to your 'little add' is to use split to extract the individual values
--
Tommy
Too stupid to live.
Too stubborn to die.
|
|---|