in reply to Regex problem

Thank your for your early responses, but my concern here is if the array @index_corr_file has something like qw(1 11 23 45 22) and suppose the $index = 2, then the grep function will be true and the if condition will pass. But i want $index to match to only 2 not otherwise. Is there any way to minimize the code. Sid

Replies are listed 'Best First'.
Re^2: Regex problem
by edan (Curate) on Feb 16, 2005 at 12:14 UTC

    If you want to test for equality, then by all means!

    if ( grep { $index == $_ } @index_corr_file ) { # whatever }
    --
    edan

Re^2: Regex problem
by prasadbabu (Prior) on Feb 16, 2005 at 12:06 UTC

    This will help you,

    grep(/^$index$/, @index_corr)

    update:

    As edan said, it will help you

    grep{$index==$_} @index_corr

    Prasad

      I downvoted your post, and I'll tell you why - IT'S WRONG! Why would you give somebody a regex solution when they clearly need to test for equality!? What if $index contained regex metacharacters? In short, I think it's a bad habit to use an anchored regex when you mean "equals". perl provides us with == and eq for a reason. Use them.

      --
      edan