There are several reasons why this proposal wouldn't work, or would be a bad idea.

First, optional tie methods have the habit of breaking inheritance. Consider a hypothetical popular CPAN module that uses a tied SCALAR. Suppose my code creates a subclass of this, where I override FETCH, with something like

sub FETCH { my $self = shift; do_domething; $self->SUPER::FETCH(@_); }
Now suppose that the CPAN maintainer updates his code to include a new FETCHSUBSTR method. I install this version, and suddenly my FETCH method is mysteriously no longer being called.

Second, given the way the perl5 interpreter works, it's not practical to combine array subscripting and substr, so it wouldn't be possible to use *SUBSTR with arrays and hashes.

Lastly, it would help if you explained how the various uses of the substr function were mapped to *FETCH calls, especially when substr is used as an lvalue, eg

$ perl586 -wle 'sub f { $_[0] = "x" } $a = "abcd"; f(substr($a,0,2)); +print $a' xcd

Dave.


In reply to Re: Tie() and substr(), proposal for SUBSTR tie object method by dave_the_m
in thread Tie() and substr(), proposal for SUBSTR tie object method by millueradfa

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.