[REBOL] Speed and Memory Management in REBOL Re:
From: bo:rebol at: 5-Sep-2000 16:37
--__REBOL--0.6.13.4.2--5-Sep-2000/16:37:39-6:00--3052
Content-type: text/plain;
princepawn,
Attached you will find an example that should allow CSV conversion of a
file of any length.
Shocked and honored that simple old %convert-csv.r is one of the most
popular scripts!
Have fun!
-Bo
On 5-Sep-2000/12:52:36-7:00, [princepawn--lycos--com] wrote:
>I was glancing at one of the most popular scripts at the REBOL archive and developed
some questions:
>
>1- Is it possible to incrementally write to a file in REBOL?
>2- Is it possible to append to a file in REBOL
>3- This script seems in-efficient and memory wasteful: it reads and entire file into
a temporary array and then converts the array. In Perl, I could do each conversion as
I read in each line and write each line out after each conversion.
>
>REBOL [
> Title: "Comma-Seperated-Values to REBOL converter"
> Date: 16-Jun-1999
> Author: "Bohdan Lechnowsky"
> Email: [bo--rebol--com]
> File: %convert-csv.r
> Purpose: <lb>
> Convert CSV files to REBOL blocks
> <rb>
> Category: [file util db text 2]
>]
>
>csv: read/lines to-file ask "Filename to convert from CSV: "
>
>block: make block! 100
>
>headings: parse/all first csv ","
>
>foreach line next csv [append block parse/all line ","]
>
>save to-file ask "Filename to save to: " head insert/only block headings
>
>Get your FREE Email and Voicemail at Lycos Communications at
>http://comm.lycos.com
>
--
Bohdan "Bo" Lechnowsky
REBOL Adventure Guide
REBOL Technologies 707-467-8000 (http://www.rebol.com)
Download the REBOL Messaging Language
The Official Source for REBOL Books (http://www.REBOLpress.com)
--__REBOL--0.6.13.4.2--5-Sep-2000/16:37:39-6:00--3052
Content-Type: application/octet-stream; name="new-csv.r"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="new-csv.r"
UkVCT0wgWwoJVGl0bGU6CSJDb21tYS1TZXBhcmF0ZWQtVmFsdWVzIHRvIFJFQk9MIENvbn
ZlcnRlciIKCURhdGU6CTUtU2VwLTIwMDAKCUF1dGhvcjoJIkJvaGRhbiBMZWNobm93c2t5
IgoJRW1haWw6CWJvQHJlYm9sLmNvbQoJ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