Re: what form of split turns a tab-delimited variable into an array with the first line as keys?

2010-04-10 Thread Robert Cole
Take a look at my Calendar Lines stack which can be found at Rev  
Online (in the menu toolbar)
The buttons call a function in the stack script which use split and  
the extents to transpose an array.

HTH,
Bob

Date: Fri, 9 Apr 2010 15:06:28 -0700 Josh Mellicker wrote:
Thanks for everyone's help.
[..snip...]

___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


what form of split turns a tab-delimited variable into an array with the first line as keys?

2010-04-09 Thread Josh Mellicker
Given a variable like this, where the first line is headers:

name  [tab]  color  [tab]  food
Trevor  [tab]  green  [tab]  salad
Sarah  [tab]  blue  [tab]  pizza
Richard  [tab]  orange  [tab]  burgers
David  [tab]  purple  [tab]  fruit

What is the best way to turn this into an array, where the array keys are the 
first line of the variable?

I have tried various forms of split by split using and split with but 
haven't found the right formula. Personally I find the documentation on the 
various forms of the split and combine commands a bit scant.

___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: what form of split turns a tab-delimited variable into an array with the first line as keys?

2010-04-09 Thread Michael Kann
Using asterisks instead of tabs, put 

name*color*food
Trevor*green*salad
Sarah*blue*pizza

into fld 1
--
Use this script:
--
on mouseUp
set the itemDelimiter to *
put fld 1 into v
put line 1 of v into headers_line
delete line 1 of v
---
put zero into line_num

repeat for each line c_line in v
add 1 to line_num
put zero into item_num

repeat for each item c_item in c_line
add 1 to item_num
put item item_num of headers_line into x
put c_item into josh_array[x][line_num]
---
-- next two lines are just
-- to view the resulting array
---
put josh_array[x][line_num] into y
put x  line_num  y  return after h
---
end repeat
end repeat

put h into fld 2
end mouseUp



--- On Fri, 4/9/10, Josh Mellicker j...@dvcreators.net wrote:

 From: Josh Mellicker j...@dvcreators.net
 Subject: what form of split turns a tab-delimited variable into an array 
 with the first line as keys?
 To: how to use Revolution use-revolution@lists.runrev.com
 Date: Friday, April 9, 2010, 2:07 AM
 Given a variable like this, where the
 first line is headers:
 
 name  [tab]  color  [tab]  food
 Trevor  [tab]  green  [tab]  salad
 Sarah  [tab]  blue  [tab]  pizza
 Richard  [tab]  orange  [tab]  burgers
 David  [tab]  purple  [tab]  fruit
 
 What is the best way to turn this into an array, where the
 array keys are the first line of the variable?
 
 I have tried various forms of split by split using and
 split with but haven't found the right formula.
 Personally I find the documentation on the various forms of
 the split and combine commands a bit scant.
 
 ___
 use-revolution mailing list
 use-revolution@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage
 your subscription preferences:
 http://lists.runrev.com/mailman/listinfo/use-revolution
 



___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: what form of split turns a tab-delimited variable into an array with the first line as keys?

2010-04-09 Thread Bob Sneidar
Just had a few rounds with split and combine, and they are not what you think 
they are. Split takes the first value in a delimited line and that becomes the 
key. The rest of the items become the elements. The commands are fairly useless 
for much of anything. 

Bob


On Apr 9, 2010, at 12:07 AM, Josh Mellicker wrote:

 Given a variable like this, where the first line is headers:
 
 name  [tab]  color  [tab]  food
 Trevor  [tab]  green  [tab]  salad
 Sarah  [tab]  blue  [tab]  pizza
 Richard  [tab]  orange  [tab]  burgers
 David  [tab]  purple  [tab]  fruit
 
 What is the best way to turn this into an array, where the array keys are the 
 first line of the variable?
 
 I have tried various forms of split by split using and split with but 
 haven't found the right formula. Personally I find the documentation on the 
 various forms of the split and combine commands a bit scant.
 
 ___
 use-revolution mailing list
 use-revolution@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your subscription 
 preferences:
 http://lists.runrev.com/mailman/listinfo/use-revolution

___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: what form of split turns a tab-delimited variable into an array with the first line as keys?

2010-04-09 Thread Björnke von Gierke
That the split and combines are useless is completely wrong. I use them all the 
time and it's a huge timesaver for manipulating x,y matrices. Of course, for 
the given Task, they do not work for what you want directly. You'll need to 
change the orientation first, for example thusly:

on mouseUp
   --assuming the example colour and food data from below
   put field 1 into theData
   split theData by column
   repeat with theKey = 1 to the number of lines in the keys of theData
  replace return with tab in theData[theKey]
   end repeat
   combine theData by return
   split theData by return and tab
   put the keys of theData --all done
end mouseUp

Of course a single line solution for switching the orientation of tables would 
be most handily, because this is really arcane. I'm sure there's other ways 
that are faster, especially when you only use repeat for each line in theData 
in combination with put after endResult, but you asked about combine and 
split ;)

Bjoernke

On 9 Apr 2010, at 17:13, Bob Sneidar wrote:

 Just had a few rounds with split and combine, and they are not what you think 
 they are. Split takes the first value in a delimited line and that becomes 
 the key. The rest of the items become the elements. The commands are fairly 
 useless for much of anything. 
 
 Bob
 
 
 On Apr 9, 2010, at 12:07 AM, Josh Mellicker wrote:
 
 Given a variable like this, where the first line is headers:
 
 name  [tab]  color  [tab]  food
 Trevor  [tab]  green  [tab]  salad
 Sarah  [tab]  blue  [tab]  pizza
 Richard  [tab]  orange  [tab]  burgers
 David  [tab]  purple  [tab]  fruit
 
 What is the best way to turn this into an array, where the array keys are 
 the first line of the variable?
 
 I have tried various forms of split by split using and split with 
 but haven't found the right formula. Personally I find the documentation on 
 the various forms of the split and combine commands a bit scant.


-- 

official ChatRev page:
http://bjoernke.com?target=chatrev

Chat with other RunRev developers:
go stack URL http://bjoernke.com/chatrev/chatrev1.3b3.rev;

___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: what form of split turns a tab-delimited variable into an array with the first line as keys?

2010-04-09 Thread Jim Ault

On Apr 9, 2010, at 8:13 AM, Bob Sneidar wrote:

Just had a few rounds with split and combine, and they are not what  
you think they are. Split takes the first value in a delimited line  
and that becomes the key. The rest of the items become the elements.  
The commands are fairly useless for much of anything.


Bob


I use split and combine often for routine processing of large data sets.
I operate several high-speed networks using the power of spit/combine.

Remember, in their simple form, they are associative arrays, not  
indexed arrays.
Using a few techniques, they become a good way to store very complex  
and multi-dimensional data sets.


For cross-tabulation or table translation it is fairly easy to setup  
up a couple temporary arrays to quickly make the tasks happen.  You  
need to remember that associative arrays use strings as keys and  
duplicate keys result in replacement.  For example, translating a  
table could result in the new keys being duplicate strings, thus some  
of the data would get lost (overwritten).  It is easy to avoid this.


Also look at Intersect and Union in the docs for ways of filtering  
arrays without the filter command.
Build a temp array with desired keys, then intersect to keep the  
qualifiers.


At some point, it is better to use a database, such as sql-type or  
Valentina.



For me, I enjoy the speed and ease-of-use, realizing that these arrays  
are not the same as indexed arrays (thus are not as powerful for  
mathematics, etc)


Jim Ault
Las Vegas

___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: what form of split turns a tab-delimited variable into an array with the first line as keys?

2010-04-09 Thread Josh Mellicker
Thanks for everyone's help.

Though Bjoernke's solution looks clever, I could not get it to work.

I ended up with this ugly thing:

function turnIntoArray p
   put line 1 of p into tHeaders
   set the itemDelimiter to tab
   repeat with x = 2 to the number of lines in p
  repeat with y = 1 to the number of items in tHeaders
 put item y of line x of p into a[x][item y of tHeaders]
  end repeat
   end repeat
   return a
end turnIntoArray

On Apr 9, 2010, at 8:56 AM, Björnke von Gierke wrote:

 That the split and combines are useless is completely wrong. I use them all 
 the time and it's a huge timesaver for manipulating x,y matrices. Of course, 
 for the given Task, they do not work for what you want directly. You'll need 
 to change the orientation first, for example thusly:
 
 on mouseUp
   --assuming the example colour and food data from below
   put field 1 into theData
   split theData by column
   repeat with theKey = 1 to the number of lines in the keys of theData
  replace return with tab in theData[theKey]
   end repeat
   combine theData by return
   split theData by return and tab
   put the keys of theData --all done
 end mouseUp
 
 Of course a single line solution for switching the orientation of tables 
 would be most handily, because this is really arcane. I'm sure there's other 
 ways that are faster, especially when you only use repeat for each line in 
 theData in combination with put after endResult, but you asked about 
 combine and split ;)
 
 Bjoernke
 
 On 9 Apr 2010, at 17:13, Bob Sneidar wrote:
 
 Just had a few rounds with split and combine, and they are not what you 
 think they are. Split takes the first value in a delimited line and that 
 becomes the key. The rest of the items become the elements. The commands are 
 fairly useless for much of anything. 
 
 Bob
 
 
 On Apr 9, 2010, at 12:07 AM, Josh Mellicker wrote:
 
 Given a variable like this, where the first line is headers:
 
 name  [tab]  color  [tab]  food
 Trevor  [tab]  green  [tab]  salad
 Sarah  [tab]  blue  [tab]  pizza
 Richard  [tab]  orange  [tab]  burgers
 David  [tab]  purple  [tab]  fruit
 
 What is the best way to turn this into an array, where the array keys are 
 the first line of the variable?
 
 I have tried various forms of split by split using and split with 
 but haven't found the right formula. Personally I find the documentation on 
 the various forms of the split and combine commands a bit scant.
 
 
 -- 
 
 official ChatRev page:
 http://bjoernke.com?target=chatrev
 
 Chat with other RunRev developers:
 go stack URL http://bjoernke.com/chatrev/chatrev1.3b3.rev;
 
 ___
 use-revolution mailing list
 use-revolution@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your subscription 
 preferences:
 http://lists.runrev.com/mailman/listinfo/use-revolution

___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: what form of split turns a tab-delimited variable into an array with the first line as keys?

2010-04-09 Thread Björnke von Gierke
Oi my solution works fine, it must b your computer that's amiss :P

No seriously, i tested it here and it did what I thought you wanted?


On 10 Apr 2010, at 00:06, Josh Mellicker wrote:

 Thanks for everyone's help.
 
 Though Bjoernke's solution looks clever, I could not get it to work.
 
 I ended up with this ugly thing:
 
 function turnIntoArray p
   put line 1 of p into tHeaders
   set the itemDelimiter to tab
   repeat with x = 2 to the number of lines in p
  repeat with y = 1 to the number of items in tHeaders
 put item y of line x of p into a[x][item y of tHeaders]
  end repeat
   end repeat
   return a
 end turnIntoArray
 
 On Apr 9, 2010, at 8:56 AM, Björnke von Gierke wrote:
 
 That the split and combines are useless is completely wrong. I use them all 
 the time and it's a huge timesaver for manipulating x,y matrices. Of course, 
 for the given Task, they do not work for what you want directly. You'll need 
 to change the orientation first, for example thusly:
 
 on mouseUp
  --assuming the example colour and food data from below
  put field 1 into theData
  split theData by column
  repeat with theKey = 1 to the number of lines in the keys of theData
 replace return with tab in theData[theKey]
  end repeat
  combine theData by return
  split theData by return and tab
  put the keys of theData --all done
 end mouseUp
 
 Of course a single line solution for switching the orientation of tables 
 would be most handily, because this is really arcane. I'm sure there's other 
 ways that are faster, especially when you only use repeat for each line in 
 theData in combination with put after endResult, but you asked about 
 combine and split ;)
 
 Bjoernke
 
 On 9 Apr 2010, at 17:13, Bob Sneidar wrote:
 
 Just had a few rounds with split and combine, and they are not what you 
 think they are. Split takes the first value in a delimited line and that 
 becomes the key. The rest of the items become the elements. The commands 
 are fairly useless for much of anything. 
 
 Bob
 
 
 On Apr 9, 2010, at 12:07 AM, Josh Mellicker wrote:
 
 Given a variable like this, where the first line is headers:
 
 name  [tab]  color  [tab]  food
 Trevor  [tab]  green  [tab]  salad
 Sarah  [tab]  blue  [tab]  pizza
 Richard  [tab]  orange  [tab]  burgers
 David  [tab]  purple  [tab]  fruit
 
 What is the best way to turn this into an array, where the array keys are 
 the first line of the variable?
 
 I have tried various forms of split by split using and split with 
 but haven't found the right formula. Personally I find the documentation 
 on the various forms of the split and combine commands a bit scant.
 
 
 -- 
 
 official ChatRev page:
 http://bjoernke.com?target=chatrev
 
 Chat with other RunRev developers:
 go stack URL http://bjoernke.com/chatrev/chatrev1.3b3.rev;
 
 ___
 use-revolution mailing list
 use-revolution@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your subscription 
 preferences:
 http://lists.runrev.com/mailman/listinfo/use-revolution
 
 ___
 use-revolution mailing list
 use-revolution@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your subscription 
 preferences:
 http://lists.runrev.com/mailman/listinfo/use-revolution

___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution