Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] Re: Creating a list, writing it in a file

From: richard:coffre:francetelecom at: 11-Apr-2002 15:11

Hi Carl, Some details, my purpose is to create a list while reading lines in a file, then to sort the list and finally to copy it in a new file so first I have to extract the lines to create the list, I don't have it. What's the weather like in New Zealand ? Richard -----Message d'origine----- De : Carl Read [mailto:[carl--cybercraft--co--nz]] Envoy=E9 : jeudi 11 avril 2002 14:04 =C0 : [rebol-list--rebol--com] Objet : [REBOL] Re: Creating a list, writing it in a file On 11-Apr-02, COFFRE Richard FTO wrote:
> Hi, > Reading lines in a file, I want to create a list which each item is > a line, e.g. : > foo > azer > redc > ertg > => > routines: ["foo" "azer" "redc" "ertg"] > Currently I use "append" as follows : > append routines ligne > But I have something with no spaces between the items, therefore > when I sort the serie it is an character sorting and I obtain > something like "acdeeefgoorrrrtz" while I want ["azer" "ertg" "foo" > "redc"]
Hi Richard, I assume you mean it's starting out as a list of lines you want to sort and not a block? ie...
>> lines: "aaa^/ccc^/bbb"
== "aaa^/ccc^/bbb"
>> print lines
aaa ccc bbb If so, first convert it to a block using parse then sort the block...
>> blk: parse/all lines "^/"
== ["aaa" "ccc" "bbb"]
>> sorted: sort blk
== ["aaa" "bbb" "ccc"] You can then save the block as a text-file using write/lines...
>> write/lines %test.txt sorted
and read it back in as either a string or a block...
>> read %test.txt
== "aaa^/bbb^/ccc^/"
>> read/lines %test.txt
== ["aaa" "bbb" "ccc"]
> At the end to copy it in a file, can I use the following instruction > forall routines [write/append/lines output first routins]
write/append/lines adds lines to an existing file, so the above would add all of routines to a file. (Typos excepted:) If you want to overwrite a current file or start a new one though, just use write/lines as I've done above, there being no need for a loop. HTH. -- Carl Read