On 05/04/00, "Carl Jolley <[EMAIL PROTECTED]>" wrote:
> On Tue, 2 May 2000, Scott K Purcell wrote:
> 
> > Hello,
> > I have a hash whose keys are organized by the values. 
> > eg.
> > %hash = (
> >       'apple' => '1',
> >       'peach' => '2',
> >       'pear' => '3',
> >       'plum' => '4',
> > );
> > 
> > And all is good.
> > 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.
> > eg.
> > apple = 1;
> > pear = 2;
> > plum = 3;


> Put the keys in a list and interate over the list creating entries
> in the hash:
> 
> $i=1;
> foreach (qw(apple pear peach plum)) {
>    $hash{$_}=$i++;
> }
> 
> if the keyss are being read in one by one, instead reading them
> all into a list and doing the above code just read each one in
> in a while loop, e.g.
> 
> open(FILE, "values.txt") || die "Missing values.txt at ";
> while(<FILE) {
>   chomp;
>   $hash{$_}=$.;
> }

This takes care of reading them in, but not deleting them with the
results that he desires. The creation of the hash in one of the above ways
can be incorporated into my previous solution using tied hashes. The
exact implementation is left up to anyone that cares.

Cheers,
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]

Reply via email to