Works on my machine, not on his machine after he edits

This is weird. I have a script I’ve written to reformat a file for this
guy. It works perfect on my Mac, but not on his.

This was a quick and dirty script to reformat an ascii file. It parses
the fixed length records and writes the output in a tab delimited
format. No big deal.

I had hard coded the file name in the script, and sent it to him, to
edit and type in the correct path names for the input and output files,
and now it does not work for him.

This is the error he gets:

Last login: Sat Jun 14 16:57:06 on console
adam-fanns-power-mac-g5:~ adamfann$ cd desktop
adam-fanns-power-mac-g5:desktop adamfann$ ruby phone_nums.rb
phone_nums.rb:1: syntax error, unexpected tIDENTIFIER, expecting $end
IO.foreawhen “S1if value[0,1]==”=" then value =
value[1,value.length-1].to_s ; eputs “…done.” ; Unknown record
type:\n\t#{t}" ;

These are some of the lines in question from my copy of the source:

infile = “/Users/toddburch/Desktop/file.txt”
outfile = “/Users/toddburch/Desktop/file_converted.txt”

out = File.open(outfile, “w”) ;
outdata = “” ;
IO.foreach(infile) {|t|
case t[0,3]
when “S01” then
if (outdata != “”) then out.puts outdata end
outdata = t[15,7] ;
when “S13” then outdata += ("\t" + t[12,1].to_s) ;
when “S14” then
value = t[16,t.strip.length-2-16]
if value[0,1]=="=" then value = value[1,value.length-1].to_s ; end
outdata += “\t” + value.to_s ;
else puts “Unknown record type:\n\t#{t}” ;
end
}

He’s using TextEdit to edit, and his Preferences are set for a plain
text file. He’s sent me his copy after he edits it, and to the eye, it
looks fine. I have to overtype his file names to run it on my machine,
and after removing that, it works fine.

Any ideas?

Thanks, Todd (posted to Ruby Forum - I may not see your reply if you
answer is directed another list)
(By the way, the link to the FAQ is not working)

On Jun 19, 10:08 am, Todd B. [email protected] wrote:

Offhand it looks to me like there’s a problem with the script’s line
endings, i.e. Ruby is expecting Unix line endings but the script has
DOS endings. The clue is that the error message seems to be claiming
that the error is on line 1, as though the entire script is one line.
I don’t know why this would be a problem if both your computer and his
are Macs, though.

On 19 Jun., 17:29, Karl von Laudermann [email protected]
wrote:

IO.foreawhen “S1if value[0,1]==”=" then value =
value[1,value.length-1].to_s ; eputs “…done.” ; Unknown record
type:\n\t#{t}" ;

Offhand it looks to me like there’s a problem with the script’s line
endings, i.e. Ruby is expecting Unix line endings but the script has
DOS endings. The clue is that the error message seems to be claiming
that the error is on line 1, as though the entire script is one line.
I don’t know why this would be a problem if both your computer and his
are Macs, though.

Another potential source might be different versions of the Ruby
interpreter.

Cheers

robert

Karl von Laudermann wrote:

I don’t know why this would be a problem if both your computer and his
are Macs, though.

Right. I use TextWrangler and have my line-end setting to be Unix (LF).
I just looked in TextEdit and it doesn’t even appear to have an option.

(I worked around the problem by writing a java program to do the same
thing… :frowning: )

Robert K. wrote:

Another potential source might be different versions of the Ruby
interpreter.

Could be, but that seems strange. Of course, the whole scenario is
strange. He’s running:

ruby 1.8.6 (2007-09-24 patchlevel 111) [universal-darwin9.0]

and I’m running:

ruby 1.8.2 (2004-12-25) [universal-darwin8.0]

Todd