Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Find Element of array but use the next Element

by packetstormer (Monk)
on Jun 15, 2012 at 07:42 UTC ( #976380=note: print w/replies, xml ) Need Help??

in reply to Find Element of array but use the next Element

If you are using 5.12 you can use this:
#!/usr/bin/perl use strict; use warnings; my @arr = ('app', 'Oracle', 'EPDMCA', 'Oracle' ,'EPZXC'); while (my($index,$value) = each @arr ) { if($value eq "Oracle") { print "Value next to Oracle is:$arr[$index+1]\n" } }

Replies are listed 'Best First'.
Re^2: Find Element of array but use the next Element
by afoken (Abbot) on Jun 15, 2012 at 20:43 UTC

    ... with the little problem that it does not like Oracle as last Element of @arr:

    my @arr = ('app', 'Oracle', 'EPDMCA', 'Oracle' ,'EPZXC','Oracle');
    Value next to Oracle is:EPDMCA Value next to Oracle is:EPZXC Use of uninitialized value within @arr in concatenation (.) or string +at line 11. Value next to Oracle is:


    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://976380]
[Corion]: A good daystart everybody!
[Happy-the-monk]: Goody-goody!

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2018-01-23 08:40 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (242 votes). Check out past polls.