At 2:00 AM -0700 9/25/10, feltra wrote:
Hi,
Am using arrays with only references in a sub-routine. While I got
the hang of how to access an element of the array using the '->'
operator, I do not know how to intialize this array. I.e. I want to
be able to do something like
@myarr=(); $#myarr = -1;
inside the subroutine, but myarr is only a reference to an array not
the actual array...
[] is the notation for a reference to an array.
For example, if you want to initialize a scalar variable so that it
contains a reference to an anonymous, empty array, you would do this:
my $myarr = [];
You can initialize the array to contain data:
my $myarr = [ 'a', 'b', 'c' ];
or
my $myarr = [ qw( a b c) ];
To copy the contents of an array into an anonymous array and save a
reference to the anonymous array:
my $myarr = [ @other_array ];
Does that help?
--
Jim Gibson
j...@gibson.org
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/