home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / perl / 5822 < prev    next >
Encoding:
Text File  |  1992-09-09  |  1.4 KB  |  37 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!caen!destroyer!ubc-cs!dhami
  3. From: dhami@cs.ubc.ca (Mandeep S Dhami)
  4. Subject: Re: class negation broken - OR - what am I doing wrong ?
  5. Message-ID: <1992Sep10.004713.25964@cs.ubc.ca>
  6. Sender: usenet@cs.ubc.ca (Usenet News)
  7. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  8. References: <1992Sep9.134920.2169@robcad.uucp>
  9. Date: Thu, 10 Sep 92 00:47:13 GMT
  10. Lines: 25
  11.  
  12. ronys@calisto.robcad.uunet (Rony Shapiro) writes:
  13. >I'd expect the following perl one-liner to print all characters except 'f':
  14. >    perl -n -e 'print if /[^f]/' file
  15.  
  16. >However, ALL of the characters are printed.
  17. >As a check,
  18. >     perl -n -e 'print unless /[f]/' file
  19. >works as expected on the same data.
  20.  
  21. >Is the problem with my understanding of [^f] ?
  22.  
  23. Yes. /[^f]/ => there exists at least one match for [^f] in $_.
  24. When $_ is "f\n", /[^f]/ matches "\n", etc. you have to use the
  25. second form (or /f/) to exclude _any_ match with f.
  26.  
  27. try:
  28. perl -ne  'print if /^[^f]/' file # to exclude beginig with f, etc. and
  29. perl -ne  'print unless /f/' file # to exclude _any_ occurence of f
  30.  
  31. Mandeep
  32. __________________________________________________________________
  33. "I'm very brave generally," he went on in a low voice:
  34. "only to-day I happen to have a headache."
  35.                                       -- Lewis Carroll
  36. __________________________________________________________________
  37.