Re: Meaning of [@tempArray]
[email protected] (Paul Lalli)
| Newsgroups | perl.beginners |
|---|---|
| Organization | http://groups.google.com |
| Message-ID | <9215c950-97c3-447c-96f5-1c97a3306024@c65g2000hsa.googlegroups.com> |
On Jun 12, 6:41 am, [email protected] (Rodrick Brown) wrote: > On Thu, Jun 12, 2008 at 5:28 AM, [email protected] <[email protected]> > wrote: > > > Hi there, > > > I am stuck with something here. > > What does the following piece of code mean? > > > my @temp1; > > my @temp2; > > $cnt=0; > > $temp2[$cnt] = [@temp1]; > > > What is the kind of data stored in $tempFieldNames[$information] ? > > Your creating a reference to an array as and storing that reference in array > index 0. > Data::Dumper can be very helpful for understanding what's going on here its > no different than doing saying $temp2[$cnt] = \@temp1; Actually, it's quite different. In the OP, $temp2[$cnt] is a reference to an anonymous array that happens to have been initialized with the data that was in @temp1 at the time it was created. In your modification, $temp2[$cnt] is a reference to @temp1. In the OP, if any following statements modify @temp1, those changes will not be reflected in @{$temp2[$cnt]}. Similarly, changes to @{$temp2[$cnt]} will not be reflected in @temp1. In your modification, changes to one will affect the other, because they're the same array. Paul Lalli