ok, so if i get this right, @dummy has the following format:
my @dummy = qw(
1996013100:00:00 MAAA
2000081100:00:00 MA-
1997063000:00:00 MAAA
1998122200:00:00 MAA
2000112400:00:00 MD
);
now we have that established, let's say that as soon as you think 'gee i
need to SORT something on ONE VALUE in this data' you should probably be
using a hash.
so that's what we'll do
what we'll do is read every line of @dummy, split it on white space and put
that as key/value pairs in a hash, like so:
my %hash = map { split /\s/ } @dummy;
this is equivalent to the more verbose:
my @data;
for my $element (@dummy) {
my ($key, $value) = split(/\s/, $element);
push(@datay, $key, $value);
}
my %hash = @data;
as you can see, the above is quite a bit more writing, slow and ugly then
the map solution, but it's more 'logical' to read for most.
also note that there's no objection to saying: %hash =
@array_with_key_value_pairs
the other way around is a bit more tricky, seeing hashes keep their
key/value pairs seemingly unordened, wheras arrays keep indexes... so you
can't say:
%hash = @array_with_key_value_pairs;
@copy_of_array_with_key_value_pairs = %hash;
and assume that
@copy_of_array_with_key_value_pairs eq @array_with_key_value_pairs;
having said that, let's see how we can get our info out of the hash like we
want to:
for (sort keys %hash) {print "$_ has value $hash{$_}\n"}
the above will print:
1996013100:00:00 is MAAA
1997063000:00:00 is MAAA
1998122200:00:00 is MAA
2000081100:00:00 is MA-
2000112400:00:00 is MD
Hope this does what you want,
hth,
Jos Boumans
<snipping stuff>
> Folks,
> # How do I sort an array by one of it's fields?
>
> # @dummy before sorting has this:
>
> 1996013100:00:00 MAAA
> 2000081100:00:00 MA-
> 1997063000:00:00 MAAA
> 1998122200:00:00 MAA
> 2000112400:00:00 MD
> I would like to sort by it by the first column, which is a date read by
> ParseDate fron Date::Manip.
</snipping stuff>