On Sunday 26 September 2010 19:14:37 Jim Gibson wrote: > 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 = []; >
There is a difference between saying: sub my_sub { my ($array_ref) = @_; $array_ref = []; } And: sub my_sub { my ($array_ref) = @_; @{$array_ref} = (); } The first code does not modify the array referenced by the original reference (which may be an anonymous one) while the second version does. I don't know what the original poster wants, though. Regards, Shlomi Fish -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ My Public Domain Photos - http://www.flickr.com/photos/shlomif/ <rindolf> She's a hot chick. But she smokes. <go|dfish> She can smoke as long as she's smokin'. Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/