[REBOL] Re: Creating a list, writing it in a file
From: joel:neely:fedex at: 12-Apr-2002 6:56
Hi, Richard,
COFFRE Richard FTO wrote:
> 1. Read the line and extract (if necessary) a function name.
>
How? "if necessary" based on what? Do you mean some sort of
syntax-driven recognition/parsing?
As for the rest, let's pretend that "a function name" is the
letter #"F" followed by one or more digits.
Here's some sample data:
8<----------begin morelines.txt----------
blah blah F123 blah blah blah F45 blah blah
yadda yadda F678 yadda yadda F123 yadda F678
bloop bloop bloop F bloop
tada tada tada tada
dum da dum dum F123 F9 dum da dum dum
8<----------morelines.txt ended----------
and here's the script that does what you described:
8<----------begin morelines.r----------
REBOL []
morelines: make object! [
names: []
digits: charset "0123456789"
fnamerule: [#"F" some digits]
run: func [fi [file!] fo [file!]] [
names: copy []
foreach line read/lines fi [
parse/all line [
any [
copy name fnamerule (
if not found? find names name [
append names name
]
)
|
skip
]
]
]
write/lines fo sort unique names
]
]
8<----------morelines.r ended----------
after saying this at the console:
>> morelines/run %morelines.txt %morelines2.txt
we have
8<----------begin morelines2.txt----------
F123
F45
F678
F9
8<----------morelines2.txt ended----------
-jn-
--
; Joel Neely joeldotneelyatfedexdotcom
REBOL [] do [ do func [s] [ foreach [a b] s [prin b] ] sort/skip
do function [s] [t] [ t: "" foreach [a b] s [repend t [b a]] t ] {
| e s m!zauafBpcvekexEohthjJakwLrngohOqrlryRnsctdtiub} 2 ]