in reply to Last Element of Hash
In which case, liz's answer is a good one, because depending on the order of the sort, you can always find not only the last key, but the last one alphanumerically, or the first one, if your sort is ascending instead.
Liz's answer is even the more useful if you're looking for the 'last' out of several hashes. In the real-life example Im giving below, I created two hashes labelled 'atoms' and 'protons'. Their keys are the actual line numbers from a flat file, where each atom/proton had it's own line.
Hence by iterating the line numbers themselves(extracted here from a 'residue'), I can get the true last atom/line of a residue.
Cheersforeach my $ref (sort keys %{$self->{'residues'}{'1'}}){ $last=$self->{'atoms'}{$ref} if defined $self->{'atoms'}{$ref}; $last=$self->{'protons'}{$ref} if defined $self->{'protons'}{$ref} +; }
|
|---|