Buddha M Buck wrote:

> > > 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;
>
> I think what he's thinking (in C terms) would be more like the following:
>
> typedef struct { int length; char *s } string;
>
> // $foo = "xyzzy";
> string foo; foo.length = 5; foo.s =
strdup("xyzzy---blank---buffer---space---");
>
> // $bar = $foo;
> string bar; bar.length = foo.length; bar.s = foo.s;
>
> // $foo .= "xyzzy";
> strncpy(foo.s+foo.length,"xyzzy",5); foo.length += 5;
>
> // $foo and $bar share string buffers, but $bar only sees the first 5
> // characters while $foo sees the first 10.
>
> I don't see that as quite the same as the implicit references or
> type-globs you suggested.
>
> But it's late, and I might not know what I'm talking about...
>

That's exactly what I mean.

But actually doing that second $foo .= "xyzzy" thing without allocating a
new string would be problematic, since if I did $bar .= "abccb" after that
in the same way that it's done for $foo, it would overwrite the "xyzzy" in
$foo, right?

- Branden



Reply via email to