Hello Perl Monks...I come today on bended knee humbly begging for any wisdom you can provide...
I am trying to find elements in an array that are positioned 1, 2 and 3 places behind my 'target' element. So if my list is: 1,2,3,4,5,6,7,8,9,8,7,6,5,4,3,2,1, and my 'target' number was 5, I am looking for a way to return elements 6,7,8, and 4,3,2, I need to get the three elements after every time a 5 appears in the list. In actual practice the list will not be sequential and will be somewhat longer, but nowhere near consuming all my memory kinda long, maybe 200-300 items max.
I can get the index of my target number easily enough, however I am wondering if there is a way I can manipulate the index values to 'look ahead'. I've been trying many variations of:
$idxvalue = (pop(@indexes)+1); print "$lines[$indexes[$idxvalue]]\n";
but I am having a hard time finding something that works. It's odd because when I print @indexes I get a list of the index numbers as expected, but then at times I am getting the actual item from the list, rather than the index position number I wanted. Please forgive my ignorance...I am trying my best....which admittedly is not very good :-(
I'm using Strawberry Perl on Windows 10 in case it matters.... Thank you in advance to any who can offer suggestions or advice! TJ.
In reply to Manipulating Array Indexes by TJ777
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |