On 05/03/00, ""Douglas Wilson" <[EMAIL PROTECTED]>" wrote:
> 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
Here, this is a bit cleaner than the previous version:
package IdxHash;
use strict;
use vars qw(@ISA);
use Tie::Hash;
@ISA = qw(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;
use strict;
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";
}
---
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]