To:       [EMAIL PROTECTED]
cc:
From:     Doug Vos
Date:     12/01/99 05:50:49 PM
Subject:  Re: [REBOL] 1000's of objects's in array - Works fine for me... Re:(3)

Please don't jump to conclusions.
I read in 1000's of records in tab delimited format every day (with rebol).
So I am not asking how to do it.
Since I aleady do it every day and my scripts sort and filter thousands of
records.

My question was based on looking for a better way to do it...

Perhaps I have a lot of code here with objects that
 I can eliminate, now that I have read the "beta-2.2/manual"
and know how to sort blocks by any field.

Previously I wrote all this code because I like sorting objects by the object
/attribute.
You can sort by any attibute and it is very easy to implement.... EASY is the
key word here.
It was very easy for me to sort objects and I had no method to sort complex
blocks...
... so that is why I went off on the tangent I did.

There is a great section in the "manual/sersort.html" about sorting
series/blocks....
Specifically there is a section with a function called "record-sort"
I won't repeat the code here... see the function called "record-sort"

I am not sure that it will sort any faster or make the program run any faster.
Because I already have a script that reads 2100 or more records and builds
webpages in a few seconds.
But...my point was  that I am always looking for a way to eliminate code and
make things smaller
and maybe faster.  I think Carl is saying that there is an easier and better way
to do it
I am including a few of my routines here.....
The function make-objects reads in all the lines and seperate the fields
(parsing for each tab.)

I think what Carl is saying is that I should not use objects and rather than
parse with the tab character.... just set the values using a SET or COMPOSE or
something
like that???

So, I guess I should not be doing parse/all {^(tab)}?? and then just
just convert the block directly to field names???

So I would possibly change it from "foreach case cases"
to..

foreach [ case-num site-name city severity
   agreement user-name user-phone etc ] cases [

   do the stuff here
   that I normally do
]

And since each record is tab-delimited I can just handle it that way
without parsing the tabs and corverting to items/objects...

Is that what Carl is talking about??

I think so, but I wish he would provide more examples of how he (or BO or
someone at REBOL) would recommend doing it......Since they wrote the
language and know why and how they put certain functions in "R".

;----------------------------------------------------------------------------
make-objects: function [
   "Returns the list/array of ticket objects (cases) from file."
   from-file
   o-cases
][
   cases o-case items
][
   cases: read/lines from-file  ; each record/line is a case and will become an
object.

   foreach case cases [
       items: parse/all case {^(tab)}   ; each field is tab delmited

       ; skip the header records
       ; skip the canadian records
       if items/5 = "United States" [
          o-case:  case-object items
          append o-cases o-case
       ]

   ] ; end of foreach loop

   return o-cases
]
;----------------------------------------------------------------------------
case-object: function [
   items
][
   o-case
][
   o-case: make object! [
       case-num: site-name: none
       city: severity: agreement: user-name: user-phone: none
       queue: assigned-to: product: svc-type: none
       status: summary: date-opened: days-open: last-inbox: none
   ]

   o-case/case-num:     items/1
   o-case/site-name:    items/4

   o-case/city:         items/6
   o-case/severity:     items/8
   o-case/agreement:    items/9
   o-case/user-name:    items/10

   either (substring items/11 1 3) = "01 " [
       o-case/user-phone: substring items/11 4 (length? items/11 )
   ][
      either (substring items/11 1 2) = "1 " [
         o-case/user-phone: substring items/11 2 (length? items/11 )
      ][
         o-case/user-phone: items/11
      ]
   ]

   o-case/queue:        items/12
   o-case/assigned-to:  items/13
   o-case/product:      items/14
   o-case/svc-type:     first parse items/9 none

   o-case/status:       items/18
   o-case/summary:      items/19
   o-case/date-opened:  to-rebol-date items/20

   o-case/days-open:    calc-days o-case/date-opened
   ;o-case/days-open:    to-integer items/22
   ; adjust for the fact that extract is run previous night
   ; --but people are viewing the next day
   ;o-case/days-open: o-case/days-open + 1

   o-case/last-inbox:   if value? items/23 [items/23]

return o-case
]
;----------------------------------------------------------------------------


























From: [EMAIL PROTECTED] on 12/01/99 05:30 PM GMT



Please respond to [EMAIL PROTECTED]



To:   [EMAIL PROTECTED]
cc:    (bcc: Doug Vos)
Subject:  [REBOL] 1000's of objects's in array - Works fine for  me... Re:(3)




Here's how:

1. convert your data files (comma delim, or whatever) to blocks.
   You can use the script on www.rebol.com in user-lib to do it.

2. Now you can loop over the data easily with a foreach or a while
   loop.

Check out the example on the web site.... then ask a few questions here.
About 5 lines of code to do what you want.

-Carl


At 12/1/99 10:47 AM -0500, you wrote:
>
>
>Please elaborate on this for process
> to handle standard comma delimited files (or tab delimited files)...
>
>Any more pointers on the words  set [ x1 x2 x3 x4 ... ] record
>
>I know about "set"  , but what is "record".... is that a word or just your
>example value.
>
>
>
>
>
>From: [EMAIL PROTECTED] on 12/01/99 03:46 AM GMT
>
>
>
>Please respond to [EMAIL PROTECTED]
>
>
>
>To:   [EMAIL PROTECTED]
>cc:    (bcc: Doug Vos)
>Subject:  [REBOL] 1000's of objects's in array - Works find for me... Re:
>
>
>
>
>And, if each record is identical, then you can skip the objects altogether.
>Instead, just map the record to variables as you need:
>
>   set [field1 field2 field3 ...] record
>
>Saves a lot of mem space....
>
>-Carl
>
>
>At 11/30/99 04:34 PM -0500, you wrote:
>>
>>
>>If you are talking simple objects - no embedded functions (in each object).
>>
>>I have scripts that do that every day with thousands of objects in a
>>block/series.
>>
>>I read in a flatfile database with about  16 fields and 1900 records...
>>converting to objects as I parse the data.
>>
>>Works great.
>>
>>So, my suggestion would be to just try it and see how large it will scale
>>before you think it won't work.
>>
>>- doug
>>
>




Reply via email to