How to specify delimiters - in relation to lists.
When you load a delimited string into a list you can now specify the delimiter used.
By default, no delimiter is a new line character, as it is expecting to read the info of a pocket variable which is delimited by new line characters (like the songlist inside the saxaphone and the messages the tiny robot trainer says).
load $actor's playlist;
print "I found a random line of $randomitem";
If you specify a comma, then a comma will be used, like this:
load "load "one,two,two,three,three,three" by ,;
print "the third in our list is $list[2] and a random item is $randomitem";
If you specify anything like a number 1, 2, n etc.. it will be wrapped in wings and turned into a numbut eg: }1{ or }2{ or even }zzz{
load "one}1{two, two}1{three, three, three" by 1;
print "the second in our list is $list[1] and a random item is $randomitem";
Another place where delimiters have entered is the old favorite.. getting a random string from a delimited string.
Now you can specify the delmiter by setting the variable $delim before you get your random item ( sorry we cant use ' by n' right now. Im working on that.)
$delim = '}1{';
$rnd = "(one}1{two, two}1{three, three, three)";
print "I found $rnd";
Things to note about this:
- the $delim is always a comma by default, but watch you you may set it in your code and forget when you net choose a random item.
- wrap your delimited list in round brackets so cow knows you want a random item from the list
- if no @list has been defined yet then the first time you do this, the @list will be set to this list, with the standard $list[n] and $randomitem etc available.
Using load will be minutely faster than using manipulate to get a dummy value just to load it into the global @list for foreach looping over.
mani $actor's skills get coding to $cod by 1;
load $cod by 2;
foreach in list do showit;
##showit: print "$for_count item is $for_key equals $for_value";
(notice we can use abbreviations to the long and complicated manipluate cowmand - this is paying hommage to google: [Black Books bbc]).