Dan Muey wrote: > > On Wednesday, June 11, 2003, at 05:14 AM, Jaschar Otto wrote: > > > > > > $string =~ s/[^abcd]//g; > > > > > > Thanks a lot, that worked perfect, > > > > Transliterate is probably a better choice for this kind of > > thing. It's > > certainly more efficient. You would use it like this: > > Just curious, how is it more efficient?
Because it doesn't involve any pattern matching. The translation is a straightforward byte for byte mapping. > Can you use anchors in tr ? You can't use regexes at all with tr//. > because in the =~ example above it would match a string: > abcd foo monkey The caret at the start of a character class negates the sense of the class, so /[abcd]/ matches a character which is any one of the four letters 'a', 'b', 'c' or 'd'. /[^abcd]/ will match any single character except these four. In the expression ($string = 'abcd foo monkey') =~ s/[^abcd]/ /g; the regex matches four times - once for each of the first four characters. > But not monkey abcd foo ($string = 'monkey abcd foo') =~ s/[^abcd]/ /g; also matches four times - starting at offset 7 within the string. > While the tr version would match both. Both have the same effect as $string =~ tr/a-d/ /; HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]