in reply to grep exact words

Because you're searching the same list multiple times, you should probably do this:
my %seen = map { $_ => 1 } @serv; foreach $ARGV (@ARGV) { if (!$seen{$ARGV}) { warn "$ARGV not found\n" next; } # Whatever you want to do when found }

We're not really tightening our belts, it just feels that way because we're getting fatter.

Replies are listed 'Best First'.
Re^2: grep exact words
by Anonymous Monk on Jun 26, 2004 at 13:36 UTC
    I tried the code you posted..it doesnt seem to be working . What is this 1 in the code here:- my %seen = map { $_ => 1 } @serv;
      %seen is a hash. map is constructing a list of key-value pairs to assign to it. Each element of @serv is a key, and 1 is the value for each. It's the same as saying
      my %seen; @seen{@serv} = (1) x @serv;
      Saying "doesn't seem to be working" is not useful. Providing your input, output, and what you expected to be different could help.

      Please do note the advice to chomp the lines you're reading from a file. "foo\n" will not be equal to "foo".


      We're not really tightening our belts, it just feels that way because we're getting fatter.