On Wed, 4 Jul 2001 hal9000 / hypermetrics.com wrote:

> > But with Ruby here, it silently does, well, I don't know:
> >
> > [gc@obiwan ~] echo -e "_123456789_" | ruby -w -pe 'sub(/
> \067/,"x")'
> > _123456x89_
> > [gc@obiwan ~] echo -e "_123456789_" | ruby -w -pe 'sub(/
> \068/,"x")'
> > _123456789_
> > [gc@obiwan ~] echo -e "_123456789_" | ruby -w -pe 'sub(/
> \070/,"x")'
> > _1234567x9_
> >
>
> I *think* I know what's happening in the second case.
> Ruby is smarter, not dumber, than you think.
> It realizes that 8 is not a valid octal digit, so you get
> a regex of an ASCII 6 followed by a character 8. Since this
> pattern is not matched, nothing happens.

Here's an example that shows this in action, so to speak:

candle:~$ echo -e "_1234567890_" | ruby -w -pe 'sub(/\0678/,"x")'
_123456x90_

(ASCII 067, i.e. '7', followed by 8)


David

-- 
David Alan Black
home: dblack / candle.superlink.net
work: blackdav / shu.edu
Web:  http://pirate.shu.edu/~blackdav