Greetings all,
I have run across something rather puzzling to me.
This would be easier to illustrate given the code:
#!/usr/bin/perl -w
use strict;
use Dumpvalue;
###how I would normally do it.
my @cells;
for(my $i=0; $i<3; $i++){
push(@cells,[[],[],[]]);
}
###a different approach.
my @othercells;
@othercells = ([[],[],[]]) x 3;
###lets check shall we?
print "Content-Type:text/html\n\n";
dump_ref(\@cells);
dump_ref(\@othercells);
exit;
###peek under the hood.
sub dump_ref
{
my $ref = shift;
my $dumper = new Dumpvalue;
print "<pre>";
$dumper->dumpValues($ref);
print "</pre>";
print "<br />";
}
This gives me
0 ARRAY(0x8135f2c)
0 ARRAY(0x813fb50)
0 ARRAY(0x812bd00)
empty array
1 ARRAY(0x812be2c)
empty array
2 ARRAY(0x812bc1c)
empty array
1 ARRAY(0x816dc88)
0 ARRAY(0x812bde4)
empty array
1 ARRAY(0x813fb5c)
empty array
2 ARRAY(0x813f8ec)
empty array
2 ARRAY(0x816dce8)
0 ARRAY(0x8135efc)
empty array
1 ARRAY(0x816dc7c)
empty array
2 ARRAY(0x816dcd0)
empty array
0 ARRAY(0x8135f20)
0 ARRAY(0x816dd48)
0 ARRAY(0x813fa48)
empty array
1 ARRAY(0x816dcdc)
empty array
2 ARRAY(0x816dd30)
empty array
1 ARRAY(0x816dd48)
-> REUSED_ADDRESS
2 ARRAY(0x816dd48)
-> REUSED_ADDRESS
My question is this: Why does the latter method reuse the address of the anonymous array?
My present understanding led me to think that both methodologies would return the same structure (namely the first dumped results), however I was
wrong! So could someone please help dispel my obfuscated understanding regarding the latter idiom?
Thanks in advance
-injunjoel
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.