Home: Perl Programming Help: Beginner:
deleting hash ref key & value


Dec 17, 2015, 1:04 AM

Views: 1649
deleting hash ref key & value

Hi folks,

Is this the right way to delete a hash? I have this portion of a script and wanted to delete the hash ref/key/value but it errored out "delete argument is not a HASH or ARRAY element or slice". TIA!

my $unwanted;
foreach my $wafer (@{$model->wafers}){
foreach my $die ( @{$wafer->dies}){
if ($die->{soft_bin} eq "") {
$unwanted = $die;
delete $wafer->dies($unwanted);


Dec 17, 2015, 10:36 AM

Views: 1625
Re: [alferic] deleting hash ref key & value

You have not given us enough information to help you. We need to see your data structures. Your for loops are valid perl only if $model and $wafer are objects. If they are, we will also need to see their code (or their documentation). If not, you must fix your code. (We probably can help with this after we see the data structure.)

The function 'delete' removes a key from a hash. Your error message is telling you that that is not what you are doing. My best guess is that you are trying to remove an element from an array. That would be very hard to do. You do not want a design that requires it. Please explain the 'big picture' of what you are trying to do.
Good Luck,