|
Pages: [1]
|
 |
|
Author
|
Topic: Array? (Read 732 times)
|
|
Stoop
|
 |
Array?
« on: February 28, 2006, 09:54:15 AM » |
|
Not sure how to handle this, either as an array or just as a block.
Anyway want to go through a log file and when a name is parsed out add that to array and give it a count of 1.
Keep going, if a new name is found, add the name to the array, make the count 1.
If a name is found that is already in the array then increase the counter to 2 .... and so on.
What is the best way to do this in REBOL, as a database? array? block?
|
|
|
|
|
Logged
|
|
|
|
nconc
Guest
|
 |
Array?
« Reply #1 on: March 09, 2006, 07:52:12 AM » |
|
REBOL []
countnames: func [name /local wrd][ wrd: to-word name if error? try [array/:wrd: array/:wrd + 1] [insert array reduce [wrd 1]] ]
array: make block! 1000 countnames "name1" countnames "name2" countnames "name1" countnames "name2" countnames "name3" probe array input
|
|
|
|
|
Logged
|
|
|
|
|
Anton
|
 |
Re: Array?
« Reply #2 on: August 21, 2006, 04:24:13 AM » |
|
Try this:
lines: read/lines %logfile ;eg. lines: [ "First name: Anton Last name: Rolls" "First name: Albert Last name: Einstein" "First name: Anton Last name: Reisacher" ]
result: copy []
foreach line lines [
name: none parse line [thru "First name: " copy name to " "] either count: select result name [ ; (select returns NONE if not found) ; already in result, bump count result/:name: count + 1 ][ ; not already in result, add it repend result [name 1] ] ]
; add new-line markers to the result block so it molds nicely new-line/all/skip result on 2
print mold result
|
|
|
|
|
Logged
|
|
|
|
|
|
Pages: [1]
|
|
|
 |