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

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;
which is, essentially, just a variation of that theme.

The answer to your 'little add' is to use split to extract the individual values

--
Tommy
Too stupid to live.
Too stubborn to die.


In reply to Re: Re: Re: Text Manipulation Quickie by tommyw
in thread Text Manipulation Quickie by johnirl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.