#!/usr/bin/perl

use warnings;

#setpriority 0, 0, 10;
select(STDOUT);
$| = 1;

##########################################
#slurp log file
open (LOG, "my_data.file");
        while (<LOG>) {
                chomp; #remove line endings
                $a = $_; #place into a normal scalar
                @z = split " ", $a; #split it into its two parts
                # we are now going to use an associtive array called a hash.
                # This has one scalar as the key (analogous to the index in a normal array)
                # and another scalar as the data. 
                $h{$z[0]} = $a; #use the first part ($z[0]) as the key and the
                # whole of the line ($a) as the data.
                # If you wanted to use the second bit as the key, use $z[1] instead (or, if you
                # had something that was split into many parts, you could combine keys, making
                # keys the same length by filling with spaces (strings from the back and numbers
                # from the front, ie '   10' and '36527' &, 'asd  ' and 'werty').
                # This sorts out any duplicates as well if you need that.
        }
close (LOG);

# Sort out keys and store them in an array
@kl = sort (keys (%h));

# write sorted file
open (SRT, ">my_sorted_data.file");
        foreach $y (@kl) {
                print SRT "$h{$y}\n";
        }
close (SRT);
