Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: popping, shifting or splicing an array???

by davidrw (Prior)
on Aug 09, 2005 at 17:24 UTC ( #482314=note: print w/replies, xml ) Need Help??


in reply to popping, shifting or splicing an array???

Depends where in the array you want to cut stuff out and if you're rmoving a single element at a time or multiple elements... splice is the most general (i think any shift or pop can be re-written as a splice), whereas shift and pop only remove a single element, and only from the very front or back (respectively) of the array.
  perldoc -f splice
  perldoc -f shift
  perldoc -f pop

so, to summarize:
if only one element from front, then shift
else if only one element from back, then pop
else splice

(Note also there are probablly different ways besides splice as well -- e.g. could probably rewrite using map/grep/array slices)

Replies are listed 'Best First'.
Re^2: popping, shifting or splicing an array???
by drock (Beadle) on Aug 09, 2005 at 17:40 UTC
    I am looking to spice off more than one element possibly up to 10 and no larger than 20 of those selected numbers from user input. 1..1000 user selects 1..5 splice array 1..5 return array with 6-1000 print new array 6-1000

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://482314]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2018-02-24 02:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When it is dark outside I am happiest to see ...














    Results (310 votes). Check out past polls.

    Notices?