Forum Discussion
tidenz_92110
Nimbostratus
Jul 26, 2010Data Class to array
Hi Guys,
I am trying to reference a new external data class and read the contents into an array.
class URL_LIST
"/help" := "www.companya.com/help/get"
foreach item [class get URL_LIST] {
set index [findstr $item "" 0 ":="]
set data [findstr $item ":=" 1 "\n"]
set LIST "$index $data"
set ::ARRAY($index) $data
however when i debug
log local0.debug [array size ::ARRAY] i get 2 entries
and if i log both index and data i only get stuff in index. so it looks like the value is not parsed into data.
any idea's i have been stuffing around but i think i am missing something basic.
Is there a better way to read a data class into an array?
Thanks
3 Replies
- hoolio
Cirrostratus
Hi Tidenz,
Which version are you testing on? This example worked for me on 10.2:log local0. "[class get my_strings_class]" if {[array exists my_array]}{ array unset my_array } foreach line [class get my_strings_class] { log local0. "Adding \$line to array: $line" set my_array([lindex $line 0]) [lindex $line 1] } log local0. "\[array get my_array\]: [array get my_array]"
Aaron - tidenz_92110
Nimbostratus
Hi Aaron,
We are running 10.1 HF1. your code fixes my issue but a question on why you used lindex instead of class element?
Reading the 10.X class command updates it states the lindex has been depreciated for class element commands - hoolio
Cirrostratus
I was assuming that you really need to use an array for some reason and that if that was true that it would be more efficient to get all of the datagroup elements in one go. Once you have the datagroup as a TCL list, it doesn't matter whether you access that data as a TCL list or not.
I was wondering if it might be more efficient to loop through the datagroup by index and use -name and -value flags on class element to populate the datagroup. I made an uneducated guess that the single class get operation and simple list commands might be more efficient compared with the class commands.
I guess we could take a step back and check what you're actually trying to do. I or others could then try to give you a more optimized solution.
Aaron
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects
