# Odd behaviour of a script when using -Ku option

**URL:** <https://www.ruby-forum.com/t/odd-behaviour-of-a-script-when-using-ku-option/146961>\
**Category:** Ruby\
**Created:** [August 27, 2008, 3:16am UTC](https://www.ruby-forum.com/t/odd-behaviour-of-a-script-when-using-ku-option/146961 "2008-08-27T03:16:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![martinos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/57b2e6/32.png) [@martinos](https://www.ruby-forum.com/u/martinos)\
**Post date:** [August 27, 2008, 3:16am UTC](https://www.ruby-forum.com/t/odd-behaviour-of-a-script-when-using-ku-option/146961/1 "2008-08-27T03:16:51Z")

</div>

I use Ruby 1.86 on a Macintosh with Leopard.

I wrote a script that looks for a particular regular expression in a  
large body of text, retrieves, sorts the hits, and prints them out to a  
file defined as outfile with the command outfile.print. The scripts were  
written with Textmate and saved to the default MacRoman character set

This has always worked. But I needed to look for a non-alphabetical  
Unicode character. So I saved the script as a UTF-8 file and ran Ruby  
with the -Ku option. Oddly enough, the program terminates with the error  
message “undefined local variable or method `outfile’ for main:Object  
(NameError)”

If instead of printing the output to a file I send it to STDOUT the  
program works. If I run the program without the -Ku option I get the  
error message “Invalid char `\357’ in expression”, which I presume is a  
complaint about the Unicode character in the regular expression.

If I remove the Unicode character and run the program with some other  
regular expression, the program runs properly and recognizes the  
outfile.print command.

Is this a bug or is there something obvious I overlooked?
