in reply to checking input using grep()

Well, if you insist on using a pattern, you have to use the \Q escape to "Q"uote all the metachars, and \E to end the quoting. Thus:

  die unless grep { /^\Q$input\E$/ } @var;

But you'd really be better off using eq:

  die unless grep { $_ eq $input } @var;

    -- Chip Salzenberg, Free-Floating Agent of Chaos

Replies are listed 'Best First'.
Re^2: checking input using grep()
by Aristotle (Chancellor) on Dec 28, 2001 at 09:28 UTC
    die unless grep $_ eq $input, @var;BLOCKs are ugly :) but I second the eq notion.

    Parham, look at quotemeta also.
      I usually avoid BLOCK constructs when I can, but even more than BLOCKs I dislike having similar-looking code that acts very different. So I like the BLOCK versions of grep and map.

          -- Chip Salzenberg, Free-Floating Agent of Chaos

        I do see your point.

        Mine is I like to regard brackets as syntactic sugar that I only use where really necessary for perl or to highlight any hidden precedence issue. I'm so used to automatically resolving long statements right-to-left without second though that when brackets automatically are "pay attention with precedence here!" signs for me. So I find it very distracting if there's many of them, and it takes me a lot longer to break up the statement into its parts.

        Once again it's a matter of taste and habit I guess - TMTOWTDI :-)