Hey, folks. I'm curious about an issue I've observed with trying to copy a tied array. In this particular case, the tie (this tie) causes the array to expand as it is looked at. What I observe happening however is that when trying to copy the tied array
@copy = @tied;
The results are functionally equivalent to
my $length = $#tied; @copy[0..$length] = @tied[0..$length];
as opposed to (what I'd more expect):
@copy = (); push @copy, $_ for @tied;
I've seen this on both 5.005 and 5.6.1 (but haven't tried 5.8).

So the question really is: is this how it should be? Is it my own stupid fault for implementing a FETCH method that actually alters the size of the tied array? If so, it should probably be explicitly documented that this is bad form. Really, I suppose that the best possible thing might be to add a FETCHALL method to the tiearray interface. Certainly, most array ties would define FETCHALL to be

sub FETCHALL { $self = shift; map { $self->FETCH[$_] } 0..$self->FETCHSIZE; }
but it would be nice to be able to override it when necessary.

Anyway, I'm just curious. Thanks.

--

For anyone curious, though, this really does not interfere with how r.pm works... at least not for perl -mr -n ... (or perl -mr -p) type stuff... since the <> operator really functions like it is shifting the contents of @ARGV, not copying the array. Also, I know that I haven't "officially" released r.pm, yet, as I'm still wading through legal processes with my employer, with respect to who owns what IP, and what they would let me do with it, etc.


In reply to Copying a tied array by etcshadow

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.