in reply to Re: grep exact words
in thread grep exact words

This is the code I have used and its not working....am I missing some syntax here?

open (FILE, "<$list") or die "$list failed: $!\n"; @srvr = <FILE>; close (FILE); foreach $ARGV ( @ARGV ) { #$exists = grep { $ARGV eq $_ } @srvr; if (!$exists) { print "Cant do this"; # exit (1); } }

20040626 Edit by Corion: Added CODE tags

Replies are listed 'Best First'.
Re^3: grep exact words
by Fletch (Bishop) on Jun 26, 2004 at 02:01 UTC

    You've probably still got line endings ("\n") on the values in @srvr. See perldoc -f chomp.

Re^3: grep exact words
by Roy Johnson (Monsignor) on Jun 26, 2004 at 12:55 UTC
    Do you know you have the exists line commented out?

    We're not really tightening our belts, it just feels that way because we're getting fatter.
Re^3: grep exact words
by Roy Johnson (Monsignor) on Jun 26, 2004 at 17:30 UTC
    open (FILE, "<$list") or die "$list failed: $!\n"; chomp(@srvr = <FILE>); #note close (FILE); foreach $ARGV ( @ARGV ) { print "Comparing <$ARGV> to\n"; $exists = grep { print " <$_>\n"; $ARGV eq $_ } @srvr; if (!$exists) { print "Cant do this"; # exit (1); } }

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