On 29/04/2011 11:13, z sway wrote: > > Hi, grow($part) returns an array, I don't know how to create a ref to array > in one step. > > @$part = grow($part) doesn't work here.To my knowledge, it is used for > changing the array $part refers to, but $part is not a ref , it‘s a string, > it can't refer anything until it's changed to a ref. > > $part = \(grow($part)) doesn't work either, it creates refs to elements in > the array.
Assigning to @$part would work fine if $part didn't already hold a value. As it is, you must either use a separate variable: my $part2; @$part2 = grow($part); or copy the return from the subroutine into an anonynous array: $part = [ grow($part) ]; But I think it would be best if the subroutine just returned a reference to an array in the first place. Rob -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/