[prog] Introduction and Perl: Flat File DB Query Question

John Clarke johnc+linuxchix at kirriwa.net
Wed Mar 15 11:16:45 EST 2006


On Tue, Mar 14, 2006 at 10:37:24 +0000, Katherine Spice wrote:
 
> The problem is that at stage B (ln 53) given your data above, you are 
> left with a zip array containing (12345, 12345, 12346, 12347).

And here's an easy way to sort that array and remove duplicates:

    sub sort_unique
    {
        my @unsorted = @_;
        my ($entry, %unique, @sorted);

        # This creates one entry in the hash for
        # each unique entry in the input array.
        foreach $entry (@unsorted)
        {
            $unique{$entry} = 1;
        }
        # 'keys %unique' returns an unsorted list
        # 
        @sorted = sort {$a <=> $b} keys %unique;
   
        return @sorted;
    }


Cheers,

John
-- 
"... it is without a doubt the most singularly pointless waste of
 technology since someone bolted two wheels to a pogo stick and called
 it a Segway."
    -- http://www.theregister.co.uk/2004/09/16/nose_driven_mouse/


More information about the Programming mailing list