Says juerd:
sub DELETE { my ($self, $key) = @_: $self->STORE($key, ''); }
That, unfortunately, doesn't work well. Suppose %h is tied to the string converted, and then you do delete @h{2,5}. You'd like to delete the n and the r, yielding coveted, but that's not what happens. Instead, Perl calls DELETE(2), which deletes the n, leaving coverted, and then DELETE(5), which deletes the t, not the r, leaving covered instead of coveted.

Of course, that's not your fault, but at present it can't really be made to work right. I was going to put in a patch to fix this (motivated by the same problem using delete with Tie::File) but I haven't gotten around to it yet. The easy solution is that if you're deleting a list of values, Perl should delete them in order from last to first instead of from first to last. That fixes the delete @h{2,5} problem, but unfortunately the same problem persists with delete @h{2,5,3}.

The patch I planned to make would allow the tied hash class to request that Perl call a special DELETESLICE method instead of making multiple calls to DELETE in such cases. It would follow the same form as the NEGATIVE_INDICES feature in the current bleadperl.

--
Mark Dominus
Perl Paraphernalia

In reply to Re: Are strings lists of characters? by Dominus
in thread Are strings lists of characters? by John M. Dlugosz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.