B
Bill H
Is there any way of accessing a Hash's keys alphabetically? For
example, if I have the following:
$ARRAY{'ABC'} = "ABC";
$ARRAY{'CDE'} = "CDE";
$ARRAY{'BCD'} = "BCD";
and try to access them with a construct like this:
foreach $temp (keys(%ARRAY))
{
print "$ARRAY{$temp}\n";
}
The order I get them when I print seems to be random, or maybe FIFO,
but the way I would want to get them back would be in order based on a
sort of the keys. The way I have gotten around this is to use the
following, which could be improved with a hammer I am sure:
foreach $temp (keys(%ARRAY))
{
$dbf[@dbf] = $temp;
}
@rbf = sort @dbf;
foreach $temp (@rbf)
{
print "$ARRAY{$rbf[0]}\n";
}
This is just sample code but illustrates what I am trying to
accomplish. I am sure there is some perlish way of doing this with a
few curly braces and slashes, but can't seem to figure it out.
Bill H
example, if I have the following:
$ARRAY{'ABC'} = "ABC";
$ARRAY{'CDE'} = "CDE";
$ARRAY{'BCD'} = "BCD";
and try to access them with a construct like this:
foreach $temp (keys(%ARRAY))
{
print "$ARRAY{$temp}\n";
}
The order I get them when I print seems to be random, or maybe FIFO,
but the way I would want to get them back would be in order based on a
sort of the keys. The way I have gotten around this is to use the
following, which could be improved with a hammer I am sure:
foreach $temp (keys(%ARRAY))
{
$dbf[@dbf] = $temp;
}
@rbf = sort @dbf;
foreach $temp (@rbf)
{
print "$ARRAY{$rbf[0]}\n";
}
This is just sample code but illustrates what I am trying to
accomplish. I am sure there is some perlish way of doing this with a
few curly braces and slashes, but can't seem to figure it out.
Bill H