in reply to to find an index of a particular value in an array

Here's a simpler quicker way; instead of the foreach loop and pattern matches which succeed on each line,

# my @lines = grep { -1 != index $_, $address } @contents; my @lines = grep { -1 != index $_, "=$address " } @contents; my @indexes = grep { -1 != index $content[$_], "=$address "; } 0 .. $#contents;
That gives all the lines containing the target $address.

Update: Skeeve++ is correct, substring amended. Added index search.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^2: to find an index of a particular value in an array
by Skeeve (Parson) on Sep 22, 2005 at 11:18 UTC
    But it doesn't give him the index and it will fail if the address is a substring of what is searched. Your code will (for example) return a line containing 201.1.1.102 when the user searched for 1.1.1.1

    $\=~s;s*.*;q^|D9JYJ^^qq^\//\\\///^;ex;print