in reply to Can I change the definition of '\s'?

It can be done using a source filter.

package Filter::BackslashS; use Filter::Simple; use strict; FILTER_ONLY regex => { s/\\s/[\\s\xA0]/g };
use Filter::BackslashS; print "\xA0" =~ /\s/ ? "Yay!\n" : "Hmmm\n";
Please note that this only changes the meaning of \s in literal regexes.

- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.

Replies are listed 'Best First'.
Re2: Can I change the definition of '\s'?
by blakem (Monsignor) on Sep 12, 2002 at 03:52 UTC
    I think you missed a sub keyword in there...
    FILTER_ONLY regex => sub { s/\\s/[\\s\xA0]/g };
    Also, this wont always work, since perl cannot nest character classes. What about these (albeit contrived) tests?
    print "\xA0" =~ /[A-Z\s]/ ? "Yay!\n" : "Hmmm\n"; print '[]' !~ /[A-Z\s]/ ? "Yay!\n" : "Hmmm\n";

    -Blake