Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Get Position of Element in an array

by happy.barney (Friar)
on Nov 16, 2010 at 13:32 UTC ( [id://871725]=note: print w/replies, xml ) Need Help??


in reply to Get Position of Element in an array

my ($pos) = grep $input[$_] eq $val, 0 .. $#input;
or create lookup table:
my ($first, $last) = ({}, {}); @$first{reverse @input} = reverse 0 .. $#input; @$last{@input} = 0 .. $#input; my $val = 'b'; print "Last index : ", $last->{$val}; print "First index : ", $first->{$val};

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-04-19 11:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found