Is there any form of text that I can use to introduce the whole of an associative array into RunRev?
In Perl I can say something similar to using put in RunRev like this.
RunRev
put varValue into hashArray[tKey]
Perl
$hash{ $key } = $value;
In Perl if I want to write a whole a hash array I can use this:
%hash = (
key1 => 'value1',
key2 => 'value2',
key3 => 'value3',
key4 => 'value4',
key5 => 'value5',
key6 => 'value6',
key7 => 'value7',
);
I use these all of the time, sometimes with hundreds of key value pairs. Short of using chunk expressions and a loop to "put" each value into a key of the array is there a way that I can write a whole associative array and introduce it into a RunRev script?
Thanks
Phil
Perl/PHP Hash array
Moderators: FourthWorld, heatherlaine, Klaus, robinmiller
-
- Posts: 179
- Joined: Sat Apr 08, 2006 11:08 pm
- Location: London, UK
- Contact:
Phil, I don't think it's all that different:
which isn't all that much more verbose than the perl example you give.
On the other hand, if you already have, lets say, a comma and return delimited list, you can use the "split" command.
so if myVar contains:
key1,value1
key2,value2
you can do
and myVar is now an array.
Also, if you have a list of values in a variable myVar, eg.
val1,val2,val3,val4,etc
and are happy to have numeric keys, you can
and myVar will be an array like so
myVar[1] = val1
myVar[2] = val2
and so on.
Best,
Mark Smith
Code: Select all
put "value1" into tArray[key1]
put "value2" into tArray[key2]
...etc
On the other hand, if you already have, lets say, a comma and return delimited list, you can use the "split" command.
so if myVar contains:
key1,value1
key2,value2
you can do
Code: Select all
split myVar by cr and comma
Also, if you have a list of values in a variable myVar, eg.
val1,val2,val3,val4,etc
and are happy to have numeric keys, you can
Code: Select all
split myVar by comma
myVar[1] = val1
myVar[2] = val2
and so on.
Best,
Mark Smith
Hi Mark,
Thanks for replying so promptly. I think that in my explanation I complicated matters. I didn't have a problem with the first bit and as you explained the notation for individual elements of is not much more verbose. It was the second part I was having problems with and as you explain that is so easy you find yourself thinking , it can't be that easy, can it.
I had a repeating loop doing stuff like this:
Which is clearly the wrong way to go.
Many thanks for the hours of frustration saved.
I suppose you can do something similar but a bit more complicated with multidimensional arrays by splitting key value lists into existing keys.
Thanks again
Phil
Thanks for replying so promptly. I think that in my explanation I complicated matters. I didn't have a problem with the first bit and as you explained the notation for individual elements of is not much more verbose. It was the second part I was having problems with and as you explain that is so easy you find yourself thinking , it can't be that easy, can it.
I had a repeating loop doing stuff like this:
Code: Select all
put the second word of tVar into tArray[tKey][1]
Many thanks for the hours of frustration saved.
I suppose you can do something similar but a bit more complicated with multidimensional arrays by splitting key value lists into existing keys.
Thanks again
Phil