World: r3wp
[I'm new] Ask any question, and a helpful person will try to answer.
older newer | first last |
Geomol 15-May-2009 [2380] | if it's *not* known beforehand |
mhinson 15-May-2009 [2381] | That looks exactly the structure I had in mind, but how do I get the data into the right part of the structure? if I have data of 3 2/1 & I know it refers to a vlan. I will have up to about 1500 of these for each file |
Geomol 15-May-2009 [2382] | If there can only be two indexs into the data, you setup those indexs, when you scan input. Something like (pseudo code): vlan: 3 idx1: 2 idx2: 1 data/:idx1/:idx2/vlan: vlan If you don't have the full data structure before you start, you might have to check like: if idx1 > length? data [ ... create the required blocks inside data ...] if idx2 > length? data/:idx1 [ ... create the required blocks inside data/:idx1 ...] |
mhinson 15-May-2009 [2383x2] | That would mean I read the input repeatedly (up to about 400 times) for each input wouldnt it? |
sorry, secont part of your message answers that option | |
Geomol 15-May-2009 [2385x2] | :-) |
You can also do it without using PARSE, if that's too much to start with. Read the input as lines with READ/LINES A line could then be: line: "vlan 3" And you can pick the parts with something like: >> copy/part line find line " " == "vlan" >> next find line " " == "3" Using PARSE is the elegant way to do it, but can be a bit tricky, until you've used it a few times. | |
Pekr 15-May-2009 [2387] | or use parse line " ", which will return block of "words" |
mhinson 15-May-2009 [2388x2] | In fact I do know the index structure, so your first example is exactly what I need. :-) How do I get the data back out of this structure please? I dont understand all the colons in it. |
The input data is the result of a lot of parsing. | |
Geomol 15-May-2009 [2390x2] | If you use integers and words as your indexâÊyou don't have colon, like in: data/2/35/vlan If you have a variable with the index, you need the colon to get the value of the variable, else REBOL will see it as a word, like in: idx1: 2 idx2: 35 data/:idx1/:idx2/vlan |
If you write data/idx1/idx2/vlan REBOL will look for the word idx1 in data, and it's not there. | |
mhinson 15-May-2009 [2392] | I can't get it to work. >> data/1/2/vlan: 3 ** Script Error: Cannot use path on none! value ** Near: data/1/2/vlan: 3 |
Geomol 15-May-2009 [2393x2] | Has you defined data? |
Have | |
mhinson 15-May-2009 [2395x2] | I dont know how to |
I have tried data: [] | |
Geomol 15-May-2009 [2397] | data: [ [ [] [vlan 0] ] ] Your data has nothing in it. To be able to write data/1/2/vlan: 3 you need to have at least one entry in data, and inside that two entries and inside that the word vlan and a value. |
mhinson 15-May-2009 [2398] | so I need to define all possiable parts of the structure before I use it. |
Geomol 15-May-2009 [2399] | eh ... yes or build the structure along the way as you pointed out, the second part of my answer was about. |
mhinson 15-May-2009 [2400] | from data/1/1/vlan to data/12/48/name that sounds a bit tricky. |
Geomol 15-May-2009 [2401] | Programming can be tricky. |
mhinson 15-May-2009 [2402x2] | :-) |
I tried to create a data structure like this i2: [[vlan []][disabled []][name []]] i1: [[i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2]] data:[[i1][i1][i1][i1][i1][i1][i1][i1][i1][i1][i1][i1][i1]] but when I try to use the structure I get data/1/3/vlan: 3 ** Script Error: Cannot use path on none! value ** Near: data/1/3/vlan: 3 Have I just made a typo? or am I barking up the wrong tree? | |
Graham 15-May-2009 [2404x2] | you've just got blocks of unevaluated blocks ( all containing the identical block ) |
create a Rebol object! instead | |
mhinson 15-May-2009 [2406] | is an object less tricky to define? |
Graham 15-May-2009 [2407x2] | you will have fewer problems |
you need to create your data structures or objects and then probe them to make sure you have it right. | |
mhinson 15-May-2009 [2409] | I have done this template: make object! [ i2: reduce [[vlan 0][disabled " "][name " "]] i1: reduce [[i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2][i2]] data: reduce [[i1][i1][i1][i1][i1][i1][i1][i1][i1][i1][i1][i1][i1]] ] record: make template [] probe record/data/13/48 returns none ol but >> probe record/data/13/48/vlan ** Script Error: Cannot use path on none! value do I need to do somthing to make it construct deeper levels? |
Graham 15-May-2009 [2410] | Have you read this ? http://www.rebol.com/docs/core23/rebolcore-10.html |
mhinson 15-May-2009 [2411] | Was looking at it, yes. but not discoverd how these deep nested levels work yet. |
Graham 15-May-2009 [2412] | well, one way would be to create the top level object and then add the other objects to the first object's members |
mhinson 15-May-2009 [2413] | oh, nest objects inside each other. I will try that. Thanks. |
Graham 15-May-2009 [2414x3] | in the above, you're expecting 20 - 30 copies of i2, but you're going to get all of them exactly the same .... |
ie. they won't be different but all will reference the same block | |
Now if i2 were an object, you need to instantiate 30 instances and append each instance to the i1 member | |
mhinson 15-May-2009 [2417] | That was not what I inteded.. Thanks for pointing that out... I am out of my depth at the moment. |
Graham 15-May-2009 [2418] | well, I think you need to work with a few small examples .. as what you're doing is way out ... |
mhinson 15-May-2009 [2419x2] | ok, this is a reduced set... but it does not work. I wonder if I have a problem with context? PortAttributesObj: make object! [ vlan: copy [] ;; will hold a number or perhaps a list of numbers e.g. 20 or 3,5,7 UpState: copy [] ;; none or "disabled" name: copy [] ;; any string ] PortNumberObj: make object! [ p1: make PortAttributesObj [] p2: make PortAttributesObj [] p3: make PortAttributesObj [] p4: make PortAttributesObj [] ;; so on up to p48: make PortAttributesObj [] ] ModuleNumberObj: make object! [ m1: make ModuleNumberObj [] m2: make ModuleNumberObj [] m3: make ModuleNumberObj [] ;; so on up to m13: make ModuleNumberObj [] ] record: make ModuleNumberObj [] |
it is not quite wat I want either, because I now have to reference my data structure lil record/m1/p2/vlan rather than the simple record/1/2/vlan | |
sqlab 15-May-2009 [2421] | I did not follow exactly your intentions, am I correct, you want to get a structure with 4 qualities? Then why you do not add for every line you are parsing your 4 elements: either with append data reduce [port disabled vlan name] or with append/only data reduce [port disabled vlan name] ? |
mhinson 15-May-2009 [2422x3] | sqlab, where would I store my data so I could retrieve it in the right sequence please? The input presents the data verticaly & I need to export it horizontaly. |
Each line I parse will have only one of the values disabled, vlan, name, & a range of ports. | |
when I have parsed the data I know it is for a vlan & the number of the vlan & the port... it is only later that I will find the same port number associated with the name. | |
sqlab 15-May-2009 [2425] | I understand, you are looking for a structure where you can later reference the qualities? |
mhinson 15-May-2009 [2426] | Yes. I neet to have a structure I can enumerate to export my output symbolicaly: input 1 3 1 fish 2 3 2 dog output 1 3 fish 2 3 dog |
sqlab 15-May-2009 [2427] | What is your primary index? |
mhinson 15-May-2009 [2428x2] | the index is in 2 parts, like 1/1 1/2 1/3 up to 13/48 |
I think the structure I want is fairly straight forward, but it seems complex to define it without doing all 1800 values manualy. | |
older newer | first last |