
Jasmine
Administrator
/ Moderator
Jul 10, 2000, 5:15 AM
Post #2 of 7
(2426 views)
|
Basically, you can extract one or more elements of a particular array using an array slice. Let's say you have an array like this: @array = qw(a b c d e f g h i j); And you want to use array elements 1, 3, 5 and 7. Here's how you could extract just those elements without using $array[1], $array[3], etc: @array2 = @array[1,3,5,7]; # @array2 contains b d f h You can also use the range (..) operator to define a start and end point for the slice. @array2 = @array[0..3]; # @array2 contains a b c d You can also mix and match... @array2 = @array[0, 4..6]; # @array2 contains a e f g Hope this helps!
|