On 05/02/00, ""Scott K Purcell" <[EMAIL PROTECTED]>" wrote:
> %hash = (
> 'apple' => '1',
> 'peach' => '2',
> 'pear' => '3',
> 'plum' => '4',
> );
> But now, if I delete an item, lets say 'peach', I need some way to move the
> values up and keep the order, just minus the one.
perldoc Tie::Hash
perldoc perltie
perldoc -f tie
You can try tied hashes. I have never used them, but here
is my first attempt at implementing one:
package IdxHash;
use Carp;
require Tie::Hash;
@ISA = (Tie::StdHash);
sub DELETE {
my $hshref = shift;
my $key = shift;
my $value = $hshref->{$key};
delete $hshref->{$key};
for (@{$hshref}{keys %$hshref}) {
$_-- if $_ > $value;
}
}
package Main;
my %hsh;
tie %hsh, 'IdxHash';
%hsh = qw(a 1 b 2 c 3);
while (my ($key, $value) = each %hsh) {
print "[$key]=[$value]\n";
}
delete $hsh{b};
while (my ($key, $value) = each %hsh) {
print "[$key]=[$value]\n";
}
HTH,
Douglas Wilson
---
You are currently subscribed to perl-win32-users as: [archive@jab.org]
To unsubscribe, forward this message to
[EMAIL PROTECTED]
For non-automated Mailing List support, send email to
[EMAIL PROTECTED]