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;
> 
> 
> I haven't came up with any creative ways yet. Does anyone have any ideas? 
> PS, it also needs to be a pretty solid solution.
>

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{$_}=$.;
}

**** [EMAIL PROTECTED] <Carl Jolley>
**** All opinions are my own and not necessarily those of my employer ****



---
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