I would use a sub hash

$Users{ User2 }{ Location } = .. ;
$Users{ User2 }{ Lastname } = .. ;
$Users{ User1 }{ Location } = .. ;

Then you can say

delete $Users{ $Section } ;

and avoid the looping.

You also get the added benefit of simpler database management if your
fetching / pushing to sql.

Dunno if that will solve your warnings problem but its a different
implementation that you may want to explore.

J

On Mon, 19 Feb 2001, Matthew Thompson wrote:

> Hi,
> I'm using the following code to delete values from a hash - I get the
> warning (I say warning as it does delete the value) below when delete is
> called. Is ther a better way of deleting values from hashes?
>       
>       foreach $item (%$self) {
>               if ($item=~/^$section\.(.*)/) {
>                       print "deleteing... $self->{$item}\n";
>                       delete $self->{$item}; 
>               }
>       }
> 
> warning:
> 
> deleteing... thompson
> Use of uninitialized value in pattern match (m//) at TutorialConfig.pm line
> 132.
> Attempt to free unreferenced scalar at TutorialConfig.pm line 131.
> 
> 
> An example of what is in the Hash array is:
> 
> user2.location = cambridge
> user2.firstname = matt
> user2.lastname = thompson
> user.location = peterborough
> user.firstname = mike
> user.lastname = duffy
> 
> The $section variable is 'user2' so the code deletes all info relating to
> user2.
> 
> Any recommendations to warning free code?
> 
> Thanks in advance,
> Matt
> _______________________________________________
> ActivePerl mailing list
> [EMAIL PROTECTED]
> http://listserv.ActiveState.com/mailman/listinfo/activeperl
> 

_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/activeperl

Reply via email to