injunjoel has asked for the wisdom of the Perl Monks concerning the following question:
This gives me#!/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 />"; }
My question is this: Why does the latter method reuse the address of the anonymous array?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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Comparing two approaches to nested data creation
by Abigail-II (Bishop) on Nov 20, 2003 at 23:41 UTC | |
|
Re: Comparing two approaches to nested data creation
by Coruscate (Sexton) on Nov 20, 2003 at 23:41 UTC |