Save Procedure help
Posted by Avarice (Avarice), 15 July 2003Code:
Alright, sorry for so many lines guys but i have to be able to output all of the variable input into a *.in file in a nice cozy design pattern. That's what $foo is for its just a string with a bunch of spaces, because i don't think you can grid during output. Sorry i'm just a beginner with this. Anyhow, during output i get an error saying "can't read int_wx(1) : no such variable. " The problem lies in the for loop with the puts commands inside of it i believe. Anyhow do you know how i can fix this problem?
Posted by admin (Graham Ellis), 16 July 2003To answer your immediate question ... you could use the info exists command to see if array members exist before you print them out, our you could use the array names command to get the name of all the array elements, and loop through the list that gives you back to print out the elements.
Are you sure that int_nrect contains a count of the number of elements in every array that you're printing out in the for loop that's giving you the problems, and are you sure that the elements are names from 1 up in sequence, with nothing missing?
Aside from your main question, you comment about $foo containing just spaces. I have a saying "If you find yourself repeating something many times, there must be a better way of doing it", but you've acknowledged that already ... I would consider writing a proc to output a value and keep calling that, and/or I would consider expanding the strings in double quotes.
Suggestion - fix problems one by one - get the for loop working first, then come back and discuss code tidies
Posted by Avarice (Avarice), 16 July 2003Alright i found out the problem. the array numbers are such as 4 6 2 3 1 5 like that they aren't in order like they should be. Is there a command that puts them in order that would be convenient or do i have to go through my script and find where they go astray?
Posted by admin (Graham Ellis), 17 July 2003I expect you have some missing values - otherwise a for loop would pick them out in numerical order... thus:
will give an error message because there is no element number 5:
If you use array names and a foreach loop, you can get all the elements but in the order they are stored in the array:
and finally if you use an lsort, you can sort the list of element names of the array:
Which gives something like what you want:
Note that everything is stored as a string in Tcl and that includes array keys - there is nothing to stop you having a named element in your array, and when sorting the list of names you need to specify the -integer option - otherwise the number 10 would occur between 1 and 2 (for example).
Posted by Avarice (Avarice), 17 July 2003Thankyou so much. I have it working now. However, i did come upon a new problem. I get an error after 5 or so saves ... "no space left on device" Is there a way to clear the space after every save?
Posted by Avarice (Avarice), 17 July 2003Also, is there anyway to align my output any commands so i can strategically place my output.
Posted by admin (Graham Ellis), 18 July 2003If you're opening a file for write access (with a w), then any file that already exists with the same name should be overwritten and if you keep using the same file name, this shoudn't result in your disc space becoming full. It could simply be that your web space was nearly full and other activity on your web site filled it - perhaps your site is so popular that your log files are growing huge, for example.
On formatting output, have a look at the format command which lets you format up strings, numbers, etc into fixed length strings which will align nicely when you output them - assuming that you're going to view the output using a fixed width font.
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: firstname.lastname@example.org • WEB: http://www.wellho.net • SKYPE: wellho