Thursday, January 28, 2010

Displaying a list in row ordered columns.

Had other things to do for the past couple of days so there's been no time for Gnocl developement. But, in response to a wiki request I came up with the following script to disaplay a list of variables in row ordered columns.

#!/bin/sh
# the next line restarts using tclsh \
exec tclsh "$0" "$@"
#---------------


package require Gnocl


set txt1 [gnocl::text]
gnocl::window -child $txt1 -defaultWidth 320 -defaultHeight 200


set data {a b c d e f g h i j k l m n o p q r s t u v w x y z
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z}


set rows(max) 6


set r 0 ;# row counter


# initialise array to hold output strings
for {set i 0 } {$i < $rows(max) } {incr i} { set rows($i) {} }


# build up the output strings
for {set i 0} {$i < [llength $data] } {incr i} {
set rows($r) "$rows($r)\t[lindex $data $i]"
incr r
if {$r == $rows(max) } {set r 0}
}


# insert int the text
for {set i 0 } {$i < $rows(max) } {incr i} {
$txt1 insert end $rows($i)\n
}

And here's what it produces:


No comments: