I am using a tied variable in perl. I often use substr to get a part of the string from the variable rather than the whole thing, but it seems that Perl uses FETCH in such a case to fetch the entire variable, then apply the substr operation and STORE the entire variable back. This seems rather innefficient to me in the case of large string as such is stored in a database. A Database migh contain megabytes of data in a container and may provide a more efficient manner of doing substring stores and fetches rather than fetching and storing the entire thing. I believe it would be a good idea to allow a STORESUBSTR and FETCHSUBSTR callback to be defined in the tied module in scalar, array, and hash tie modules. If STORESUBSTR and FETCHSUBSTR are not defined then Perl simply could revert back to the FETCH and STORE for getting the string, applying the substring change or extracting a substr, and storing back, as Perl does currently, assuring backwards compatability.

STORESUBSTR stores a string into a substring. If offset is 0, then none of the text in the original string is replaced, but rather the string is inserted into the string at $length. If offset is specified, than the bytes from $length to $length+$offset are replaced by $replacestr.

For arrays and hashs, the it would be called as this: STORESUBSTR ($obj, $key, $length, $offset, $replacestr);, and with scalars this: STORESUBSTR ($obj, $length, $offset, $replacestr);. It returns the substring replaced: return ($orig_value);.

FETCHSUBSTR requests a substr from a string.

For arrays and hashs, the it would be called as this: FETCHSUBSTR ($obj, $key, $length, $offset);, and with scalars this: FETCHSUBSTR ($obj, $length, $offset);. It returns the substring value: return ($value);.

In reply to 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.