Skip Menu |

This queue is for tickets about the Tie-DxHash CPAN distribution.

Report information
The Basics
Id: 41881
Status: resolved
Worked: 2 hours (120 min)
Priority: 0/
Queue: Tie-DxHash

People
Owner: Nobody in particular
Requestors: BARTL [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.03
Fixed in: (no value)



Subject: delete on a tied hash returns an unusable value
Try the following script: #!/usr/bin/perl use Tie::DxHash; tie %h, 'Tie::DxHash', ( r => 'red', g => 'green', g => 'greenish', b => 'blue' ); $deleted = delete $h{b}; use Data::Dumper; print Dumper \%h, $deleted; This produces a rather surpising output (at least, to me): $VAR1 = { 'r' => 'red', 'g' => 'green', 'g' => 'greenish' }; $VAR2 = bless( { 'occurrences' => { 'r' => 1, 'g' => 2 }, 'ckey' => 3, 'data' => [ { 'value' => 'red', 'key' => 'r' }, { 'value' => 'green', 'key' => 'g' }, { 'value' => 'greenish', 'key' => 'g' } ], 'iterators' => { 'r' => 1, 'g' => 1 } }, 'Tie::DxHash' ); In short: delete returns the tied object, not the value that got deleted from the hash, as any normal hash would do, and as is expected of a hash. In other words, I had expected to see: $VAR1 = { 'r' => 'red', 'g' => 'green', 'g' => 'greenish' }; $VAR2 = 'blue'; Don't ask me what I would have expected if the tied hash contained more than one value for this key. Maybe in list context, it could return a list of all values that all got deleted? No idea what to expect in scalar context, probably just one of the values. Of course, none of this happens, instead, it produces a similar result as the above test, i.e. delete returns the tied object.
delete now returns a reference to a list of the removed values. If no values were removed, it returns a reference to the empty list. Thanks for the spot.