From: Robert Date: 2004-07-10T19:32:37+09:00 Subject: Re: Anomoly using pattern to remove superfluous final \, if present Richard Lionheart wrote: > Hi Robert, > > >>>My goal was to chop a final backslash it was immediately preceded >>>by another backslash. >> >>Ok, then my suggestion was not a solution to your problem. > > Au contraire ... that's my feeble at French, a language I can't speak :-) > I think your suggestion *was* essentially a solution to my problem. It > merely need the tweak I mentioned, as follows. > > >>> So I'll use: >>> >>>s.chop! if /\\\\$/ =~ s >> >>Personally I would not use chop! since it is rather meant to remove record >>separators (similar to chomp! but not as sophisticated, see here: >>http://www.ruby-doc.org/docs/rdoc/1.9/classes/String.html#M001293 > > > As I read it (in the section entitled "str.chop => new_str"), the web page > your referenced indicates that chop is intended to remove *any* last > character; it merely has special semantics for record separators to > transcend the divergence of Windows from Unix. Well, yes. Technically that's true. Maybe I made the fault to put it into the same bag with chomp, which is what I usually use when reading files. >>In your case I'd prefer >> >>s.sub!( /\\\\\z/, '\\' ) > > > I assume "z" is a typo for "$" and I further assume that using pattern > matching is much less efficient than directly "chopping" (though the > difference is imperceptible for the amount of data usually processed by > scripting languages.) Well, if you really want to know it benchmark the two vs. each other and see which one is faster. When it comes to performance, intuition is often wrong. Measuring is the only way to get reliable results. > I apologize for belaboring this point. Again, I'm in your debt for your > thoughtful responses. You're welcome Kind regards robert