X
xhoster
Arrays hold some kind of special light-weight reference to it's scalar
members, but of course the reference it holds are not held in full scalars,
as that would cause an infinite regress. Is there some way to manipulate
these light-weight references directly?
The code below makes a copy of all the data in $y:
$ perl -le 'my @x=1..10; my $y = "x"x1e7; $x[0]=$y'
This codes doesn't make a copy, but now I need to manually derefence
it when I want to retrieve it from @x:
$ perl -le 'my @x=1..10; my $y = "x"x1e7; $x[0]=\$y'
And this code just doens't work:
$ perl -le 'my @x=1..10; my $y = "x"x1e7; \$x[0]=\$y'
Can't modify single ref constructor in scalar assignment at -e line 1, at EOF
I think the above code makes it clear what I intended to do, change the SV
that a certain array slot is referencing to be a different SV. Is there a
fundamental reason that Perl cannot be made to this, or is it simply that
it hasn't been coded that way?
A similar question goes for concatenating arrays--is there a way to
accomplish something like push @x,@y but having the scalars contained in @y
be directly incorporated into the end of @x, rather than being copied into
new scalars that are on the end of @x? (unlike the original, I don't know
what syntax would be used to imply this operation)
Xho
members, but of course the reference it holds are not held in full scalars,
as that would cause an infinite regress. Is there some way to manipulate
these light-weight references directly?
The code below makes a copy of all the data in $y:
$ perl -le 'my @x=1..10; my $y = "x"x1e7; $x[0]=$y'
This codes doesn't make a copy, but now I need to manually derefence
it when I want to retrieve it from @x:
$ perl -le 'my @x=1..10; my $y = "x"x1e7; $x[0]=\$y'
And this code just doens't work:
$ perl -le 'my @x=1..10; my $y = "x"x1e7; \$x[0]=\$y'
Can't modify single ref constructor in scalar assignment at -e line 1, at EOF
I think the above code makes it clear what I intended to do, change the SV
that a certain array slot is referencing to be a different SV. Is there a
fundamental reason that Perl cannot be made to this, or is it simply that
it hasn't been coded that way?
A similar question goes for concatenating arrays--is there a way to
accomplish something like push @x,@y but having the scalars contained in @y
be directly incorporated into the end of @x, rather than being copied into
new scalars that are on the end of @x? (unlike the original, I don't know
what syntax would be used to imply this operation)
Xho