Analyzing
map {$_ eq 'Oracle'? ($x):($x=$_)[2]} reverse @arr
Ok - reading backwards, the first thing that happens, is @arr gets "reversed".

Next we process each element of the reversed array. If 'Oracle' is found, we return "$x". You way well ask - what is $x, and where did it get a value?

That happens if $_ does NOT match. In that case, what happens is:
* $x gets assigned the current element
* a temporary LIST is generated because of the () - this contains ($x)
* We index index into the second element ($x)[2] which does not exist
*resulting in an EMPTY list
*That gets sent to "map" which ignores that.

SO - the only elements that "map" returns is the $x value when the current element is 'Oracle'. In this case, $x contains the value of the previous element, and because we are 'reversed', in real life, it contains the 'next' element.

There is a potential complaint that the order of the returned values is reversed.
This is easily fixed by throwing a 'reverse' in front of the 'map'.

             I hope life isn't a big joke, because I don't get it.
                   -SNL


In reply to Re^3: Find Element of array but use the next Element by NetWallah
in thread Find Element of array but use the next Element by emjga

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.