Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

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 (Monsignor) 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]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2016-10-28 02:13 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (374 votes). Check out past polls.