From: Max Maischein Date: 2001-12-17T06:51:00+09:00 Subject: [ruby-talk:28713] Re: How do you do "character filtering" of a stringusing each_byte. Luckily, I've stayed out of the flames themselves ... > > [New and revised requirements for the transliteration routine] > Pardon, but every response up until your last message answered the > question above. You later redefined the problem with hexadecimal > ,octal, and binary representations thrown in. Those, 'hacks' you > derided are one of ruby's great strengths when it comes to string > manipulation, and you said nothing about not using regular expressions > for this problem. If you insist on coding in the style of your original > post, why not use C and pick up that little speed boost? My guess is that the problem we are witnessing here is more the problem of language culture. If one comes from a language with "duct tape" mentality (as encouraged for example by Perl) to Ruby, the main tool for string manipulation are regular expressions. If one tries to apply the C/Java mindset and hopes to escape the Perl/RE mindset in Ruby, one will be vastly disappointed, as most people who do string manipulation have at least witnessed the power of Perl Regular Expressions and thus those REs are the canonical and to most, the natural way of approaching string munging. While we are at the REs, I found that the Ruby REs use their own RE implementation (arguably a good step, but getting the Perl REs to work is harder I guess), and so far only one change between the "standard" Perl REs and the Ruby REs has bitten me (and this is a change that I find quite good) - Ruby always operates in /m mode and only \A and \Z mean start and end of string respectively. Is there a comparision table between Perl REs and Ruby REs (except J. Friedels next book) ? Of course, this is no Perl advocacy list, and with the "refined" set of requirements, the Ruby way of doing things is an iterator, which I would have to be simulated under Perl with a split() and a map() statement, not as elegant as the Ruby solution ... -max PS: If you think that Perl Regular Expressions are a weird concept hardly to be grasped by a mere mortal and eschewed by the gods themselves, have a look at the Lisp string formatting operators as documented under http://www-2.cs.cmu.edu/Groups/AI/html/cltl/clm/node200.html