On 8/9/05, DBSMITH wrote: > > Hello ... > > I am trying to figure out, which operator to use; pop, shift or splice. > My goal is, as an option is selected from user input, pop or splice or > shift elements off ( those selected from user input ) and repopulate array > with remaining elements. >
Hi, First of all, I don't grok your "splice" examples. According to 'perldoc -f splice' (http://perldoc.perl.org/functions/splice.html), the second argument to splice should be an offset - i.e. a number. So "@numbers to remove" will be interpreted in scalar context, and the offeset into @ArrayA will be the lengh of the list of numbers to remove. Is that what you wanted? A second point is that you use "shift" inside a "for" loop. That's *BAD*: "If any part of LIST is an array, foreach will get very confused if you add or remove elements within the loop body, for example with splice. So don't do that." (perldoc perlsyn) "pop" removes that last value of an array (shortning the array). "shift" also shortens the array, but by removing the first element. Which one you want to use depends on what your array looks like and what you want to do. In any case you don't need to "repopulate" the array - both pop and shift change the array itself. Finally, note that "splice" can 'emulate' both operators - see the "splice" perldoc page for examples. HTH, -- Offer Kaye -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>