PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > Works on my machine, not on his machine after he edits
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Works on my machine, not on his machine after he edits

Réponse
 
LinkBack Outils de la discussion
Vieux 19/06/2008, 15h08   #1
Todd Burch
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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)
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Vieux 19/06/2008, 16h29   #2
Karl von Laudermann
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Works on my machine, not on his machine after he edits

On Jun 19, 10:08 am, Todd Burch <pro...@burchwoodusa.com> wrote:
>
> 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}" ;
>


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.
  Réponse avec citation
Vieux 19/06/2008, 16h40   #3
Robert Klemme
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Works on my machine, not on his machine after he edits

On 19 Jun., 17:29, Karl von Laudermann <doodpa...@mailinator.com>
wrote:
> On Jun 19, 10:08 am, Todd Burch <pro...@burchwoodusa.com> wrote:
>
>
>
> > 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}" ;

>
> 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
  Réponse avec citation
Vieux 19/06/2008, 17h01   #4
Todd Burch
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Works on my machine, not on his machine after he edits

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.. )
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Vieux 19/06/2008, 19h16   #5
Todd Burch
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Works on my machine, not on his machine after he edits

Robert Klemme 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
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 05h22.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10502 seconds with 13 queries