Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: pop and shift not reversible ( while @array )

by Anonymous Monk
on Mar 20, 2020 at 12:19 UTC ( [id://11114515]=note: print w/replies, xml ) Need Help??


in reply to pop and shift not reversible

while( @array ){ my $next = shift @array; }
  • Comment on Re: pop and shift not reversible ( while @array )

Replies are listed 'Best First'.
Re^2: pop and shift not reversible ( while @array )
by gannett (Novice) on Mar 20, 2020 at 17:53 UTC
    Thank you for your combined wisdom. I see this also works but looks a bit inelegant.
    my @q = ( 1,2,0,4 ); $first = pop @q; print "q $#q pop ",$first,"->"; while ($#q+1) { $next = pop @q ; print ",",$next }; ---- Gives q 2 pop 4->,0,2,1
    I would be using the offered solution.
    while( @array ) { my $next = shift @array; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (7)
As of 2024-04-24 10:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found