Loading ...
Sorry, an error occurred while loading the content.
 

Re: [PBML] Exists in an array

Expand Messages
  • Jeff 'japhy' Pinyan
    ... You don t want a regex. Regexes are for PATTERNS. You don t have a pattern, you have a constant string you want to compare against. unless grep { $_ eq
    Message 1 of 4 , Sep 26, 2002
      On Sep 26, Joe Catanzaro said:

      >That all makes sense. I'm trying to build on your
      >second example by inserting a $var into the regular
      >expression so that I can grep for $var, but it doesn't
      >seem to be working. What's the correct syntax? I've
      >been trying:
      >
      >..... unless grep {/\$var/} @array;

      You don't want a regex. Regexes are for PATTERNS. You don't have a
      pattern, you have a constant string you want to compare against.

      unless grep { $_ eq $var } @array;

      But...

      >Any other suggestions?

      ... don't use grep() for this problem. Read the FAQ about it.

      perldoc -q 'contains'

      --
      Jeff "japhy" Pinyan japhy@... http://www.pobox.com/~japhy/
      RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
      ** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
      <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
      [ I'm looking for programming work. If you like my work, let me know. ]
    Your message has been successfully submitted and would be delivered to recipients shortly.