Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: array pop

by MidLifeXis (Prior)
on Sep 10, 2012 at 12:56 UTC ( #992752=note: print w/ replies, xml ) Need Help??


in reply to array pop

pop(...) for ( 0 .. 5 );

--MidLifeXis


Comment on Re: array pop
Download Code
Re^2: array pop
by Anonymous Monk on Sep 10, 2012 at 13:12 UTC

    thank you, how can we find which elements have deleted? how can we save it in an array? thank you very much

      It depends. Are there any other requirements that you are going to dribble out?

      I would not use the approach I gave if I wanted to save what was removed. I would probably use splice instead. Additional requirements may change that answer.

      --MidLifeXis

      Your questions are a little vague, but maybe this will help:

      #! perl use strict; use warnings; my @array = ('a' .. 'e'); print 'Original @array contents: ', join(', ', @array), "\n"; my @popped; unshift @popped, pop @array for 1 .. 3; print '@array now contains: ', join(', ', @array), "\n"; print 'The deleted elements: ', join(', ', @popped), "\n";

      Output:

      Original @array contents: a, b, c, d, e @array now contains: a, b The deleted elements: c, d, e

      See also Data: Arrays.

      Athanasius <°(((><contra mundum

        or more clearly, concisely and efficiently:

        #! perl use strict; use warnings; my @array = ('a' .. 'e'); print 'Original @array contents: ', join(', ', @array), "\n"; my @popped = splice @array, 0, 3; print '@array now contains: ', join(', ', @array), "\n"; print 'The deleted elements: ', join(', ', @popped), "\n";

        splice is your friend.

        True laziness is hard work

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://992752]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (18)
As of 2014-08-28 13:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (261 votes), past polls