On Sat, 10 Feb 2001, Branden wrote:

> Suppose I have a string stored in $foo, say, "abcbca", and then I do:
>
>     $bar  = $foo;
>     $foo .= "xyzyzx";
>
> I see two ways of doing this: one is allowing a string value to be shared by
> two or more variables, and the other one not.

Why would you want to share the string value?  Why did you assign the
value of $foo to $bar if you really wanted to:

   $bar = \$foo;

Or actually closer to what you seem to want:

   *bar = \$foo;

Although a little birdy told me we're dropping globs for Perl6.  Don't
most programmers do assignment for a reason?  Why should we second-guess
them?

> Given mark-and-sweep or other advanced GC, which of them is better? Sharing
> the value or cloning on each assignment?

I don't believe implementing copy-on-write for scalars has anything to do
with garbage collection.  Any garbage collector that will work for Perl
will need to work with references.  All you're suggesting is a
beneath-the-covers reference, right?

What's the point?  You seem to be engaging in some extreme and bizarre
form of premature optimization.

-sam



Reply via email to