Forum Discussion
ldesfosses
Cirrus
Mar 26, 2018Access a table in the implemention
Hi,
I've a table that I don't know how to access.
It's received by the Implementation, if I print it :
puts "table $mytable"
I have this :
table {{
name lala
nodeaddr 8.5.2.1
port 80
}} {{
name lolo
nodeaddr 5.2.1.4
port 80
}}
How can have access to it ?
If I try to list every item :
foreach item $mytable {
puts "item{name}"
}
I have an error.
Thanks for your help.
- ldesfosses
Cirrus
I've written this :
set tmpstring [string map {\{\{ \{} $mytable] set mytable [string map {\}\} \}} $tmpstring] foreach item $mytable { set nextisname 0 set tmpitem [string trim $item] foreach line [split $tmpitem] { if { $line eq "name" } { set nextisname 1 } else { if { $nextisname eq 1 } { puts "name $line" set nextisname 0 } } } }
Not my proudest code, but it allow me to access the value.
- cjunior
Nacreous
Hi dude,
I can't see that values represent a table structure, because I think tables have just rows and columns values.
set table {{name nodeaddr port}} lappend table {lala 8.5.2.1 80} lappend table {lolo 5.2.1.4 80} foreach row $table { puts $row } name nodeaddr port lala 8.5.2.1 80 lolo 5.2.1.4 80
So I think you need a hash with named items like this way:
set hash "{name lala nodeaddr 8.5.2.1 port 80} {name lolo nodeaddr 5.2.1.4 port 80}" foreach value $hash { array set item $value puts "$item(name) | $item(nodeaddr) | $item(port)" unset item } lala | 8.5.2.1 | 80 lolo | 5.2.1.4 | 80
Best Regards.
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