> -----Original Message----- > From: nkuipers [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, July 23, 2002 2:13 AM > To: [EMAIL PROTECTED] > Subject: RE: How to make @array2 use values of @array1? > > > What I am about to raise, I do so more out of wanting someone > to educate me > than disagreeing for the sake of. The *that syntax shown > below is unfamiliar > to me outside the context of referencing a filehandle in a > subroutine params > list, where it is optional (ie., &some_sub(*STDIN)).
See perldoc perldata, under the heading "Typeglobs and Filehandles", and perldoc perlmod, under the heading "Symbol Tables" > *that > reminds me an > awful lot of a C pointer, however. Can someone clear this up for me? > > I found the following in the Camel 3rd edition, page 257, > which, though I may > be wrong, looks like it does what is requested? > > @reflist = \(@x); #interpolate array, then get refs > > which looks an awful lot like > > @array2 = \(@array1); Right, but it's a lot different than *array2 = \@array1; The first syntax: @array2 = \(@array1) is distributing the reference operation over each element of @array1 and assigning those references to @array2. Fire up your perl debugger and try the following: $ perl -d -e 1 Default die handler restored. Loading DB routines from perl5db.pl version 1.07 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::(-e:1): 1 DB<1> @array1 = qw(foo bar baz) DB<2> @array2 = \(@array1) DB<3> x @array2 0 SCALAR(0x80f82dc) -> 'foo' 1 SCALAR(0x82c7e64) -> 'bar' 2 SCALAR(0x82c7ca8) -> 'baz' DB<4> So you can see that each entry in @array2 is a reference to the corresponding entry in @array2. Now, try the other syntax: DB<4> *array2 = \@array1 DB<5> x @array2 0 'foo' 1 'bar' 2 'baz' DB<6> x \@array1, \@array2 0 ARRAY(0x82c7ce4) 0 'foo' 1 'bar' 2 'baz' 1 ARRAY(0x82c7ce4) -> REUSED_ADDRESS DB<7> So, *array2 = \@array1 makes the name @array2 and alias for @array1, i.e. they are two names for the same data (at address 0x82c7ce4 in the example above). HTH -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]