Karim BELABAS on Wed, 10 Dec 2003 09:57:52 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

RE: Reading in a file


On Tue, 9 Dec 2003, McLaughlin, James wrote:
> That works!! Thanks.
>
> I also got the write to a file part figured out.
>
>> Does
>>
>> (19:41) gp > read( "C:/Documents and Settings/jmclaugh/Desktop/fu37.txt" )
>>
>> work ?

OK, I think I understand the problem [ still no acces to Windows today... ]

1) Filename with embedded spaces are bad: GP strips unquoted spaces.

2) So you need to enclose the name in quotes, making it a character string.

3) There are special evaluation rules for strings, in which '\' plays a
prominent role, as an "escape character", consistent with traditionnal C/C++
syntax. That's section 2.6.6: Strings and Keywords in User's Manual (recent
versions). In particular

    \n --> carriage return
    \t --> TAB(ulation)
    \e --> ESC(ape)
    \x --> x for any other x including \ or "

4) This obviously conflicts with DOS ways of separating path pieces using
'\'. Fortunately, the OS itself does not care, and you can use / instead
of \ as I did above.

5) \r "C:/Documents and Settings/jmclaugh/Desktop/fu37.txt" should work

6) \r "C:\Documents and Settings\jmclaugh\Desktop\fu37.txt" is presumably
interpreted as
   \r "C:Documents and SettingsjmclaughDesktopfu37.txt"
which won't work. But
   \r "C:\\Documents and Settings\\jmclaugh\\Desktop\\fu37.txt"
should also work.

Btw, to write to a file, you can use either write() as above or \w
[ there's also writebin() whose output to a file is larger but much faster
to load ].

Be sure to either replace '\' path separators with '/' or by '\\'
(I much prefer the former).

Hope this helps,

    Karim.
-- 
Karim Belabas                     Tel: (+33) (0)1 69 15 57 48
Dép. de Mathématiques, Bât. 425   Fax: (+33) (0)1 69 15 60 19
Université Paris-Sud              http://www.math.u-psud.fr/~belabas/
F-91405 Orsay (France)            http://pari.math.u-bordeaux.fr/  [PARI/GP]