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

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" } }


Comment on Re: Find Element of array but use the next Element
Download Code
Re^2: Find Element of array but use the next Element
by afoken (Prior) 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 976380.pl line 11. Value next to Oracle is:

    Alexander

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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (18)
As of 2015-07-02 13:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (40 votes), past polls