# Different results in command-line vs. TextMate

**URL:** <https://www.ruby-forum.com/t/different-results-in-command-line-vs-textmate/191747>\
**Category:** Ruby\
**Created:** [July 17, 2010, 2:03pm UTC](https://www.ruby-forum.com/t/different-results-in-command-line-vs-textmate/191747 "2010-07-17T14:03:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_ASBlack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b4bc9f/32.png) [@David\_ASBlack](https://www.ruby-forum.com/u/David_ASBlack)\
**Post date:** [July 17, 2010, 2:03pm UTC](https://www.ruby-forum.com/t/different-results-in-command-line-vs-textmate/191747/1 "2010-07-17T14:03:41Z")

</div>

Hi –

I was working on an answer to James R.'s question, and discovered  
the following somewhat puzzling (to me) thing.

James’s text file has some non-printing (Word-derived?) characters,  
instead of regular spaces:

> > text = File.read(“lines.txt”)  
> > =\>  
> > “Clark\302\240\302\240\302\240\302\240\302\240\302\240Kent\302\240[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\302\240\r\nPop\302\240Eye\302\240\302\240\302\240\302\240\302\240\302\240\302\240\302\240\302\240\302\240\302\240\302\240\302\240\302\240[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\302\240\r\n”  
> > puts text  
> > ClarkÂ Â Â Â Â Â KentÂ [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)Â  
> > PopÂ EyeÂ Â Â Â Â Â Â Â Â Â Â Â Â Â [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

What’s odd is that when I try to scan these lines, I get different  
results depending on whether I’m on the command line or in TextMate.  
From the command line:

$ cat parse.rb  
lines = File.readlines(“lines.txt”)  
p RUBY\_DESCRIPTION  
p lines.map {|line| line.scan(/\w+/) }

$ ruby parse.rb  
“ruby 1.8.7 (2008-05-31 patchlevel 0) [i686-darwin9.8.0]”  
[[“Clark”, “Kent”, “super”, “fakeplace”, “com”], [“Pop”, “Eye”,  
“popeye”, “fakeplace”, “com”]]

And from TextMate, using command-r:

“ruby 1.8.7 (2008-05-31 patchlevel 0) [i686-darwin9.8.0]”  
[["Clark Kent ", “super”, “fakeplace”, “com”, " "], ["Pop Eye  
", “popeye”, “fakeplace”, “com”, " "]]

As you can see, it’s not just the display that’s different. The scan  
operation actually produced different results.

It feels like some kind of Heisenbug but I can’t puzzle it out.

David

–  
David A. Black, Senior Developer, Cyrus Innovation Inc.

The Ruby training with Black/Brown/McAnally  
Compleat Philadelphia, PA, October 1-2, 2010  
Rubyist [http://www.compleatrubyist.com](http://www.compleatrubyist.com)

---

<div class="post-metadata">

**Author:** ![David\_ASBlack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b4bc9f/32.png) [@David\_ASBlack](https://www.ruby-forum.com/u/David_ASBlack)\
**Post date:** [July 17, 2010, 3:57pm UTC](https://www.ruby-forum.com/t/different-results-in-command-line-vs-textmate/191747/2 "2010-07-17T15:57:50Z")

</div>

On Sat, Jul 17, 2010 at 3:03 PM, David A. Black [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> James’s text file has some non-printing (Word-derived?) characters,  
> instead of regular spaces:

Those are nonbreak spaces (U+00A0, 0xC2A0) that should be treated as \W.

What’s odd is that when I try to scan these lines, I get different

> results depending on whether I’m on the command line or in TextMate.

I thought the CRLF line endings might have something to do with it, but  
the  
result was the same. Another clue, with 1.9.1-p378, the result from  
TextMate  
was correct, identical to that of the command line.

Ammar

---

<div class="post-metadata">

**Author:** ![David\_ASBlack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b4bc9f/32.png) [@David\_ASBlack](https://www.ruby-forum.com/u/David_ASBlack)\
**Post date:** [July 17, 2010, 4:37pm UTC](https://www.ruby-forum.com/t/different-results-in-command-line-vs-textmate/191747/3 "2010-07-17T16:37:02Z")

</div>

Hi –

On Sat, 17 Jul 2010, Ammar A. wrote:

> > 
> 
> I thought the CRLF line endings might have something to do with it, but the  
> result was the same. Another clue, with 1.9.1-p378, the result from TextMate  
> was correct, identical to that of the command line.

Thanks for checking. It turns out to be an encoding thing: TextMate  
invokes Ruby with -KU. Without the -KU (which involved editing an  
underlying script file, as well as the Bundle Editor entry, but then  
again I’m not a bit TextMate bundle expert), it ran the same as the  
unadorned command line.

David

–  
David A. Black, Senior Developer, Cyrus Innovation Inc.

The Ruby training with Black/Brown/McAnally  
Compleat Philadelphia, PA, October 1-2, 2010  
Rubyist [http://www.compleatrubyist.com](http://www.compleatrubyist.com)
