This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Array and file save

Old posts that have not been replied to for several years.
Locked
c
chinchin

Array and file save

Post by chinchin »

I searched these forums all day yesterday and have been unable to find anything on this so here goes. I was wanting to write an array and save that information to a file and then pull that information from that file. Does anyone know how to do this or can give me an example. I have searched numerous websites only to find an array definition and not much help.

Thanks for your help in advance!
User avatar
GodOfSuicide
Master
Posts: 463
Joined: Mon Jun 17, 2002 8:00 pm
Location: Austria

Post by GodOfSuicide »

well, you didnt search well enaught

Code: Select all

proc write_array {name file} { 
  set fp [open $file w] 
  puts $fp [uplevel 1 [list array get $name]] 
  close $fp 
} 

proc read_array {name file} { 
  set fp [open $file r] 
  uplevel 1 [list array set $name [read -nonewline $fp]] 
  close $fp 
} 
it was in my "backup vars in file" or somth like that thread, i think slenox himself provided that code
c
chinchin

Saw that

Post by chinchin »

I didn't know exactly what uplevel was and also what {name file} meant.
Can you put something like C:\text.txt as the name?
User avatar
GodOfSuicide
Master
Posts: 463
Joined: Mon Jun 17, 2002 8:00 pm
Location: Austria

Post by GodOfSuicide »

asume yer array is called myarray
either you have a global array then you call it with "write_array myarray array.txt" / "read_array myarray array.txt" /

of you have a local array then you have to use the code from inside that proc in your own
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Re: Saw that

Post by user »

chinchin wrote:I didn't know exactly what uplevel was and also what {name file} meant.
Can you put something like C:\text.txt as the name?
Uplevel executes commands in a different scope. One level up means where ever the proc was called from. (so GodOfSuicide is wrong in his previous post)
'name' is the name of your array, 'file' is the name of the file to fetch the contents from.
Have you ever read "The Manual"?
c
chinchin

Clear

Post by chinchin »

Thanks for all the help. Now it is much clearer!! But I have one more question. Where does the file array.txt lie in the directory structure of the PC for like say Windows 2000?
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

Probably in your bot's dir. If you're not sure, why don't you give a full path instead of just array.txt?
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Re: Clear

Post by user »

chinchin wrote:Thanks for all the help. Now it is much clearer!! But I have one more question. Where does the file array.txt lie in the directory structure of the PC for like say Windows 2000?
Probably in the directory returned by 'pwd' (usually where your .conf resides) unless you've changed your working directory using 'cd' or specify an absolute/relative path. (eg: C:/path/to/file.txt or ../name.ext) Forward slashes are usually okay on windrops too, because cygwin does transparent translation of paths.
Have you ever read "The Manual"?
c
chinchin

Great news

Post by chinchin »

Thanks for the quick and informative reply. This board has got some good peeps on it.
Locked