in reply to Re^2: Reference to sort results
in thread Reference to sort results
generates a list, containing the values in the hash.keys %bigHash
Manipulates the list according to the sort rule (sorts in ascending numerical order of the value associated with the key). Still a list.sort {...}
the brackets tell Perl that "hey, this list in here? gimme a ref to an array with those elements in that order. This is the first point where it's an array in your example. It's unclear where you think copying an array is occurring. There's no practical difference between[...] #now the brackets
andmy @foo=sort @bar; return \@foo;
unless you try to manipulate the array in the subroutine, in which case you'd need to deal with @$foo in the second example. sort operates on a list and returns a list. If you use an array to feed it, it doesn't change the original array. The array you're worried about copying isn't an array yet at that point, so there's no risk of copying it.my $foo=[sort @bar]; return $foo;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Reference to sort results
by Anonymous Monk on Aug 06, 2009 at 10:42 UTC | |
by ssandv (Hermit) on Aug 06, 2009 at 15:18 UTC | |
by Marshall (Canon) on Aug 07, 2009 at 00:09 UTC | |
by omnifish (Initiate) on Aug 10, 2009 at 09:45 UTC |