home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!caen!destroyer!ubc-cs!dhami
- From: dhami@cs.ubc.ca (Mandeep S Dhami)
- Subject: Re: class negation broken - OR - what am I doing wrong ?
- Message-ID: <1992Sep10.004713.25964@cs.ubc.ca>
- Sender: usenet@cs.ubc.ca (Usenet News)
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- References: <1992Sep9.134920.2169@robcad.uucp>
- Date: Thu, 10 Sep 92 00:47:13 GMT
- Lines: 25
-
- ronys@calisto.robcad.uunet (Rony Shapiro) writes:
- >I'd expect the following perl one-liner to print all characters except 'f':
- > perl -n -e 'print if /[^f]/' file
-
- >However, ALL of the characters are printed.
- >As a check,
- > perl -n -e 'print unless /[f]/' file
- >works as expected on the same data.
-
- >Is the problem with my understanding of [^f] ?
-
- Yes. /[^f]/ => there exists at least one match for [^f] in $_.
- When $_ is "f\n", /[^f]/ matches "\n", etc. you have to use the
- second form (or /f/) to exclude _any_ match with f.
-
- try:
- perl -ne 'print if /^[^f]/' file # to exclude beginig with f, etc. and
- perl -ne 'print unless /f/' file # to exclude _any_ occurence of f
-
- Mandeep
- __________________________________________________________________
- "I'm very brave generally," he went on in a low voice:
- "only to-day I happen to have a headache."
- -- Lewis Carroll
- __________________________________________________________________
-