Lines Matching refs:array
65 A reference is a scalar value that I<refers to> an entire array or an
76 to an array, you can recover the entire array from it. If you have a
82 an entire array, and references are scalars, so you can have a hash of
102 $aref = \@array; # $aref now holds a reference to @array
109 $xy = $aref; # $xy now holds a reference to @array
115 Sometimes you want to make an array or a hash that doesn't have a
122 C<[ ITEMS ]> makes a new, anonymous array, and returns a reference to
123 that array. C<{ ITEMS }> makes a new, anonymous hash, and returns a
127 # $aref now holds a reference to an array
140 @array = (1, 2, 3);
141 $aref = \@array;
145 that it doesn't create the superfluous array variable C<@array>.
147 If you write just C<[]>, you get a new, empty anonymous array.
159 You can always use an array reference, in curly braces, in place of
160 the name of an array. For example, C<@{$aref}> instead of C<@array>.
167 @a @{$aref} An array
168 reverse @a reverse @{$aref} Reverse the array
169 $a[3] ${$aref}[3] An element of the array
174 left-hand versions operate on the array C<@a>. The right-hand
175 versions operate on the array that is referred to by C<$aref>. Once
176 they find the array they're operating on, both versions do the same
188 for doing the same thing to a regular array or hash, and then replace
189 the array or hash name with C<{$reference}>. "How do I loop over an
190 array when all I have is a reference?" Well, to loop over an array, you
193 for my $element (@array) {
197 so replace the array name, C<@array>, with the reference:
220 most common thing to do with an array or a hash is to extract a single
230 If C<$aref> holds a reference to an array, then C<< $aref->[3] >> is
231 the fourth element of the array. Don't confuse this with C<$aref[3]>,
232 which is the fourth element of a totally different array, one
240 bizarre results when your program gets array and hash elements out of
249 First, remember that C<[1, 2, 3]> makes an anonymous array containing
250 C<(1, 2, 3)>, and gives you a reference to that array.
259 @a is an array with three elements, and each one is a reference to
260 another array.
262 C<$a[1]> is one of these references. It refers to an array, the array
263 containing C<(4, 5, 6)>, and because it is a reference to an array,
265 third element from that array. C<< $a[1]->[2] >> is the 6.
267 two-dimensional array; you can write C<< $a[ROW]->[COLUMN] >> to get
268 or set the element in any row and any column of the array.
346 and gets the value, which is a reference to an array of cities in that country.
348 we can recover the array by saying
351 @cities = @array;
353 except that the name C<array> has been replaced by the reference
354 C<{$table{$country}}>. The C<@> tells Perl to get the entire array.
371 empty anonymous array of cities, and installs a reference to it into
374 Line 6 installs the city name into the appropriate array.
375 C<$table{$country}> now holds a reference to the array of cities seen
378 push @array, $city;
380 except that the name C<array> has been replaced by the reference
382 referred-to array.
396 C<$table{$country}>, which is a reference to an array, and push
397 C<$city> into the array. But
402 to push C<Athens> onto an array that doesn't exist, so it helpfully
403 makes a new, empty, anonymous array for you, installs it into
408 array, so it created a new empty array and installed a reference to it
409 in the hash automatically. And as usual, Perl made the array one
438 This doesn't copy the underlying array:
442 You get two references to the same array. If you modify
446 To copy the array, use
450 This uses C<[...]> notation to create a new anonymous array, and
451 C<$aref2> is assigned a reference to the new array. The new array is
452 initialized with the contents of the array referred to by C<$aref1>.
463 for array references.
481 C<"foo"> as an array reference, it's taken to be a reference to the
482 array C<@foo>. This is called a I<soft reference> or I<symbolic