Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: Array?
Pages: [1] Print
Author Topic: Array?  (Read 754 times)
Stoop
Newbie
*
Offline Offline

Posts: 10


View Profile
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


Email
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
Jr. Member
**
Offline Offline

Posts: 66

Rebol veteran


View Profile WWW
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] Print 
Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: Array?
Jump to:  

  
Quick Search...

Advanced search
  
Welcome, Guest. Please login or register.
Did you miss your activation email?
November 21, 2008, 05:24:11 AM
Username: Password: Session Length:
  

News: 01-09-08

Alpha version of REBOL 3 has been released!


  
2290 Posts in 593 Topics by 3742 Members
Latest Member: CorHorgeExpex

  Rebol Talk Forum | Powered by SMF 1.0.9.
© 2001-2005, Lewis Media. All Rights Reserved.

RT design by Defiant Pc