I don't know if this test is conclusive, but from the result of the following script, it looks like the answer to your question is "no":
use strict;
use warnings;
my @x = 1..10;
print '@x is at ', \@x, "\n";
$#x = -1;
my @y = 1..5;
print '@y is at ', \@y, "\n";
print '@x is at ', \@x, "\n";
__END__
@x is at ARRAY(0x8165ccc)
@y is at ARRAY(0x8183ab0)
@x is at ARRAY(0x8165ccc)
Update: OK, so the script above is not conclusive, as ikegami points out (in fact, as it turns out, it leads to the wrong conclusion).
Devel::Peek is a better tool to answer this question. With the better information I must reject my earlier hypothesis: the answer is "yes" (i.e. space does get reused).
Note that memory location 0x811b400 originally occupied by $x[ 0 ], is occupied by $y[ 0 ] afterwards.
use strict;
use warnings;
use Devel::Peek;
my @x = 1..3;
print "Dump of \@x:\n";
Dump \@x;
$#x = -1;
my @y = 1;
print "\nDump of \@y:\n";
Dump \@y;
print "\nDump of \@x:\n";
Dump \@x;
__END__
Dump of @x:
SV = RV(0x8138618) at 0x811b574
REFCNT = 1
FLAGS = (TEMP,ROK)
RV = 0x8128d68
SV = PVAV(0x811c904) at 0x8128d68
REFCNT = 2
FLAGS = (PADBUSY,PADMY)
IV = 0
NV = 0
ARRAY = 0x8154d00
FILL = 2
MAX = 3
ARYLEN = 0x0
FLAGS = (REAL)
Elt No. 0
SV = IV(0x81286a8) at 0x811b400
REFCNT = 1
FLAGS = (IOK,pIOK)
IV = 1
Elt No. 1
SV = IV(0x81286ac) at 0x811b4b4
REFCNT = 1
FLAGS = (IOK,pIOK)
IV = 2
Elt No. 2
SV = IV(0x81286a4) at 0x811b538
REFCNT = 1
FLAGS = (IOK,pIOK)
IV = 3
Dump of @y:
SV = RV(0x8138618) at 0x811b4b4
REFCNT = 1
FLAGS = (TEMP,ROK)
RV = 0x8144dc8
SV = PVAV(0x811c95c) at 0x8144dc8
REFCNT = 2
FLAGS = (PADBUSY,PADMY)
IV = 0
NV = 0
ARRAY = 0x814abd8
FILL = 0
MAX = 3
ARYLEN = 0x0
FLAGS = (REAL)
Elt No. 0
SV = IV(0x81286a8) at 0x811b400
REFCNT = 1
FLAGS = (IOK,pIOK)
IV = 1
Dump of @x:
SV = RV(0x8138618) at 0x811b4b4
REFCNT = 1
FLAGS = (TEMP,ROK)
RV = 0x8128d68
SV = PVAV(0x811c904) at 0x8128d68
REFCNT = 2
FLAGS = (PADBUSY,PADMY)
IV = 0
NV = 0
ARRAY = 0x8154d00
FILL = -1
MAX = 3
ARYLEN = 0x811b574
FLAGS = (REAL)
the lowliest monk
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.