Hi Tim,

1. Your code causes an error, before it completes executing:
>> fp: open/lines/write %test.txt
>>   forall fp
** Script Error: forall expected body argument of type: block.
** Where: forall fp


2. help open states that:
>> help open
Opens a new port connection.
Arguments:
    spec --  (file url port object block)
Refinements:
    /write -- Write only.  Disables read operations.

The /write refinement disables read operations!


Solution:

Use the /mode refinement with a block [lines read write] like this:

>> print read %test.txt
line one
line two
line three
line five

>> fp: open/mode %test.txt [lines read write]

forall fp [ 
  if found? find first fp "three" [ 
    insert next fp "line four" 
  ] 
]
== false
>> update fp
>> close fp
>> print read %test.txt
line one
line two
line three
line four
line five



;- Elan >> [: - )]

Reply via email to