Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Manipulating Array Indexes

by Corion (Patriarch)
on Sep 07, 2020 at 16:16 UTC ( [id://11121444]=note: print w/replies, xml ) Need Help??


in reply to Manipulating Array Indexes

If you want array elements, why do you use pop ? This modifies the array in question...

Maybe you can show us your code that "almost" works and tell us how it fails for you.

The simplest approach to get the next three items after a given index I can think of is:

use feature 'signatures'; sub next_three_items( $array_ref, $index ) { return $array_ref->[$index+1], $array_ref->[$index+2], $array_ref->[$index+3], ; }

... but maybe I have not understood your requirements well...

Replies are listed 'Best First'.
Re^2: Manipulating Array Indexes
by perlfan (Vicar) on Sep 07, 2020 at 16:36 UTC
    I noticed the use of pop, also. It's also taking elements from the RHS of the list which may not be intuitive in this application. The index of elements to the left of the tail of the array would not be affected, but the overall size of the array certainly is so any number derived from it will certainly change.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2024-04-20 00:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found